Thank you for the replies, however this has to be done in the templates of umbraco. The problem I seem to be having is the inabilty to create a razor statement and pass parameters into the templates.
It may not be pretty, and it may throw off the syntax highlighting/coloring in the CodeMirror web editor, but this should work:
<div id="comments" style="<umbraco:Macro runat="server" language="cshtml">
@{
if (Model.commentsClosed)
{
@("display:none;")
}
else
{
@("display:block;")
}
}
</umbraco:Macro>">
COMMENT STUFF IN HERE
</div>
Notice the inline macro is completely contained within the div's style attribute. Nothing unbalanced. I use this same trick in one of my own templates!
Just out of interest, why are you using "display:none" to disable comment functionality ? Your comments could be re-enabled very easily by even a novice hacker using firebug etc.
Wouldn't you be better off only displaying the div at all if comments are NOT closed ?
Inline Razor in HTML
I am trying to get a div tag to dynamically change its visibilty by using a property in umbraco
Something like this but in the <div> tag in the HTML
@{
if(Model.commentsClosed)
{
@:<div id="comments" style="display: none;">
}
else
{
@:<div id="comments">
}
}
I have even tried just creating a macro for this, however it wont work due to the fact that the <div> are not balanced. VERY FRUSTRATING!
Any help greatly recieved!
Hi,
You ca do it like this:
<divid="comments" @if(Model.commenstClosed){<text>style="display:none;"</text>}">
....
</div>
Create the optional class, id, style ... then add it to the element
Thank you for the replies, however this has to be done in the templates of umbraco. The problem I seem to be having is the inabilty to create a razor statement and pass parameters into the templates.
<div id="comments" style='@(Model.commentsClosed ? "display: none;" : "")'>
<umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>
<div id="respond">
<h3>Post a comment</h3>
<div class="formcontainer">
<umbraco:Macro FormGuid="d63ecae9-5ef9-41ce-bc9b-d9445949c861" Alias="umbracoContour.RenderForm" runat="server"></umbraco:Macro>
</div>
</div>
</div>
<umbraco:Macro runat="server" language="cshtml">
@{var optionalStyle = Model.commentsClosed ? "" : String.Format(" style=\"{0}\"", "display: none");}
<div id="comments" @Html.Raw(optionalStyle)> ...
</umbraco:Macro>
<umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>
...
</div> --> close comments div
When I do what you suggested, it closes the comments div tag:
<div title="Macro Tag: 'BlogPostListComments'" style="border: 1px solid rgb(0, 0, 153); "/>
<div id="respond">
<h3>Post a comment</h3>
<div class="formcontainer">
</div>
</div>
strange, works for me. Maybe the problem is your macros? Try this:
It's the macro's, but they need to be there, they are the things I am trying to disable/enable. Any idea's?
try the contour macro and the other one seperate to further track down the problem.My guess is the contour one will be ok.
If it's only one or the other, post the source here.
It may not be pretty, and it may throw off the syntax highlighting/coloring in the CodeMirror web editor, but this should work:
Notice the inline macro is completely contained within the div's style attribute. Nothing unbalanced. I use this same trick in one of my own templates!
Best of luck to you!
Just out of interest, why are you using "display:none" to disable comment functionality ? Your comments could be re-enabled very easily by even a novice hacker using firebug etc.
Wouldn't you be better off only displaying the div at all if comments are NOT closed ?
is working on a reply...