<br /> inside <div> tag wont work MVC - asp.net-mvc

I've got problem with this line:
<div class="TrescPotwierdzTresc">#Model.Article</div>
The problem is with "br" tag inside #Model.Article wont work. I can see this tag after page load, but text is still in the same line. WHen i do something like this:
<div class="TrescPotwierdzTresc">#Model.Tresc br #Model.Tresc</div>
The br tag between "#Model.Tresc" elements work fine. Do You have any idea why is that happening ?

Try this:
<div class="TrescPotwierdzTresc">#Html.Raw(Model.Article)</div>
Html.Raw returns markup that is not HTML encoded.

Related

<g:set> variable's value is not being rendered properly

I've used <g:set> tag like this:
<g:set var="extraStyle" value="style='min-width:120px;'"/>
and used the extraStyle variable like this:
<div class="myClass" ${extraStyle}> ${myValue}</div>
And it should be rendered as:
<div class="myClass" style="min-width:120px;"> XYZ </div>
But, I am getting this instead:
<div class="myClass" style="'min-width:120px;'"> XYZ </div>
Due to which, min-width style is not being applied. What am I doing wrong here?
Grails version: 3.1.6
You could try just setting the style value e.g.
<g:set var="extraStyle" value="min-width:120px;"/>
<div class="myClass" style="${extraStyle}"> ${myValue}</div>
I think Mike's answer is correct, and although I do not know the context of your project I think it might in the long run be better to add a class dynamically to the element.
Something like
<div class="myClass ${extraClass}">...</div>

SLIM h3 inside p

If I want to put header tag h1..h5 into p it render HTML in wrong way:
slim
p
h3 Header here
span Just text
expected
<p>
<h3>Header here</h3>
<span>Just text</span>
</p>
in real it render
<p></p>
<h3>Header here</h3>
<span>Just text</span>
<p></p>
looks like nothing special but in this case I can't bind CSS style because structure renders in broken way.
Is it a bug? Or I can solve this in some way?
You can not define tags like h3 and span inside the p tag.
See HTML5 specification for more information.
Slim itself doesn’t care about the tags, and renders your code as you expect:
$ slimrb
p
h3 Header here
span Just text
produces:
<p><h3>Header here</h3><span>Just text</span></p>
which matches what your expected code, except for whitespace.
This isn’t valid HTML though, so when the browser parses it it will correct it to something valid. For example the Chrome inspector will show:
<p></p>
<h3>Header here</h3>
<span>Just text</span>
<p></p>
Where the browser has closed the p element before the next h3 element.
If you want this to work in the browser, make sure you are generating valid HTML. Perhaps use a div instead of a p?

#content $key= vs #if in dust

I have the following code:
{#data.merchantModel}
<div class="address">
{#content $key="content:combinedAddr" merchantAddress1="{merchantAddress1}" merchantAddress2="{merchantAddress2}"/}
</div>
{:else}
<div class="address">{merchantAddress1}</div>
more code...
{/data.merchantModle}
I'm working with Webcore/NodeApp but everything after the {:else} doesn't get rendered. If I comment it out everything is fine. Not sure why webcore doesn't like the {:else} but was wondering if there's another way to write the above code?
Still trying to wrap my head around dust.
Looks like you need to close your content tag and model is misspelled on the closing tag:
{#data.merchantModel}
<div class="address">
{#content $key="content:combinedAddr" merchantAddress1="{merchantAddress1}" merchantAddress2="{merchantAddress2}"/}
</div>
{:else}
<div class="address">{merchantAddress1}</div>
more code...
{/content}
{/data.merchantModel}

Display Razor markup as text

I want to show a piece of Razor markup as a text example on a page. I need to show following code (for example)
<div class="editor-wrap">
<div class="editor-label">
<text>
#Html.LabelFor( model => model.StartDate, new { data_tooltip_message = "Some text" } )
</text>
</div>
</div>
so I have regular Html plus Razor markup, I know that to show Html you have to wrap it with
<XMP>
tag, but Razor is parsing its markup anyway and is throwing exception where I want it only to display plain text. Thanks in advance
<XMP> is not recommended actually. Something like <code> or <pre> is preferred. Alternatively you can HTML encode the text so that it's rendered the way you expect on the page..
Update: Sorry, I see what your trying to do now. The tag only tells the browser to stop parsing HTML, but razor still tries to parse it's code because of the # character. To get around this escape the character by putting a second # in there.
<xmp>
<div class="editor-wrap">
<div class="editor-label">
<text>
##Html.LabelFor( model => model.StartDate, new { data_tooltip_message = "Some text" } )
</text>
</div>
</div>
</xmp>

Inline if statement in grails

Is there a way in Grails to do conditionals inline on an HTML attribute, for example:
<div class="${if(sec.isLoggedIn()) loggedInClass}">
I'm trying to add a class to certain elements if the user is logged in.
This might work for you:
<div class="${(sec.isLoggedIn()?loggedInClass:null)}">
Or Try this:
<div class="${(sec.isLoggedIn()?'loggedInClass':'null')}">
You can do:
<div class="${sec.loggedIn ? 'loggedInClass' : ''}">

Resources