Liftweb eager_eval and inserting html from db - lift

I need to execute snippets like:
<div class="lift:firstSnippet.content?eager_eval=true">
<p>Some text</p>
<div class='lift:secondSnippet.showAddNewForm>'></div>
</div>
So in my template I have
<div class="lift:firstSnippet.content?eager_eval=true"></div>
FirstSnippet insert some html from db:
def content = "*" #> Unparsed(page.open_!.content.is)
That html looks like:
<p>Some text</p><div class='lift:secondSnippet.showAddNewForm>'></div>
But SecondSnippet doesnt execute. I also tried to use S.eagerEval(Unparsed(page.open_!.content.is))
but result is same. I can't figure out why.

I don't know if you copied your template code over or re-typed it, but there's a syntax error:
<div class="lift:firstSnippet.content?eager_eval=true">
<p>Some text</p>
<div class='lift:secondSnippet.showAddNewForm>'></div>
</div>
Note the > at the end of secondSnippet.showAddNewForm>
I think it should read:
<div class="lift:firstSnippet.content?eager_eval=true">
<p>Some text</p>
<div class='lift:secondSnippet.showAddNewForm'></div>
</div>
Please try that and see if it makes a difference.

Related

remove tag and add additional css class to data-sly-resource

Here's my code and I want to add another css class toggleable-content to the existing code:
<sly data-sly-resource="${'item' # resourceType='components/header'}"></sly>
This code would look something like this:
<section aria-label="aria label">
<ul class="row">
<li class="col">
<div class="body px-3">
<h2 class="h3">
body
</h2>
<p>body text</p>
</div>
</li>
</ul>
</section>
I want to remove section tag and add another css class toggleable-content to the <ul> tag. Below is what I'd like to achieve:
<ul class="row toggleable-content">
<li class="col">
<div class="body px-3">
<h2 class="h3">
body
</h2>
<p>body text</p>
</div>
</li>
</ul>
I was wondering how to use slightly to achieve the above? I tried something below but it doesn't work:
<sly data-sly-resource="${'item' # resourceType='components/header', cssClassName='toggleable-content'}"></sly>
Assuming the section markup is managed by the included resource (components/header) then you cannot do it directly. Indirectly, with AEM, you can pass a parameter (through request attributes) and retrieve it in the components/header model, then add the section conditionally (using data-sly-unwrap for example).
Or you re-organize your code and switch from resource inclusion to template calling and pass the parameter directly using data-sly-call.

Functionality of data-sly-test for given example in image

Please find the below snippet. Can any one explain above functionality for the data-sly-test. How it will work condition here for image??
<div class="spon-image-container col-12 col-md-4">
<sly data-sly-test="${properties.fileReference}">
<img class="spon-_image" src="${properties.fileReference}"/>
</sly>
</div>
There are a few things to mention here. The gist of the code snippet is, that the <img> tag will only be rendered if {$properties.fileReference} is not empty.
Be aware, there is no sanity check involved here. data-sly-test won't check if the referenced file exists etc.
So assume that ${properties.fileReference} equals /content/dam/myImage.png. Then the resulting HTML would like this:
<div class="spon-image-container col-12 col-md-4">
<img class="spon-_image" src="/content/dam/myImage.png"/>
</div>
On the other hand, if the ${properties.fileReference} is empty (or null) you get the following HTML:
<div class="spon-image-container col-12 col-md-4">
</div>
Depending on your HTML/CSS/JS you might not want that to happen. So you could improve your code to include the data-sly-test statement in the <div> tag:
<div class="spon-image-container col-12 col-md-4" data-sly-test="${properties.fileReference}">
<img class="spon-_image" src="${properties.fileReference}"/>
</div>
This way, the <div> is only rendered, if a fileReference is set. But even if you still want the <div> to appear, your code can be improved by removing the <sly> element and adding the data-sly-test to the <img> tag:
<div class="spon-image-container col-12 col-md-4">
<img class="spon-_image"
src="${properties.fileReference}"
data-sly-test="${properties.fileReference}"/>
</div>
As mentioned in the specification, data-sly-test:
Keeps or removes the element depending on the attribute value.
For your case if fileReferece property evaluates to true (not null, not empty), it will render:
<div class="spon-image-container col-12 col-md-4">
<img class="spon-_image" src="....."/>
</div>
Note that the sly tag unwraps/removes itself, it's actually unnecessary here as the data-sly-test attribute could be moved to the img.
If fileReference evaluates to false, it will render:
<div class="spon-image-container col-12 col-md-4">
</div>
It basically checks if the current resource properties(i.e component properties) contain fileRefernce then it will add an image tag.

Remove ce-wrappers of fluid cObject

I masked(mask-extension) a couple of plug-ins. When the image is generated in the template, it is always wrapped in following divs:
<div id="c63" class="frame frame-default frame-type-image frame-layout-0">
<div class="ce-image ce-center ce-above">
<div class="ce-gallery" data-ce-columns="1" data-ce-images="1">
<div class="ce-outer">
<div class="ce-inner">
<div class="ce-row">
<div class="ce-column">
<figure class="image"><img class="image-embed-item"
src="fileadmin/user_upload/bla" width="975"
height="678" alt=""></figure>
</div>
</div>
</div>
</div>
</div>
</div>
Is there any way to remove all those wrappers? I simply want to have the image.
Sidenotes:
1. f:image does not work, I cannot access the proper uid for it to show. (This is perhaps an issue with mask)
2. I cannot find the tt_content.stdWrap.innerWrap > in my typoScript, as I do not know where mask puts it. It is neither in the netup.ts nor in the NewContentElementWizard.ts
You need to overwrite the fluid_styled_content partial in Resources/Private/Partials/Media/Gallery.html.
How to overwrite, you can read here: https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/8.7/Configuration/OverridingFluidTemplates/

how to check handlebar-template completely rendered

i have a handlebar-template in B.phtml file like this:
<div class="conversation-header" id="conversation-header" >
<div class="avatar">
<a href="{{profileUrl}}">
{{> avatar showHardcore=false}}
</a>
</div>
</div>
This template is going to append A.html file which have been add eventlistener 'load' then will do something.
But it can't check exactly when the handlebars-template completely rendered.
May i have a callback for B.phtml or sth like that and can i write this on A.phtml ?

jQuery: getting current selector's inner html PLUS selector's header (outer html)

Using jQuery, I've got a selector -- call it $('#someDiv1') -- that I'd like to get the inner HTML for, but also the header of the tag as well. So given this HTML structure..
<div id="parentDiv">
<div id="someDiv1">
<div id="innerDiv1_1"></div>
<div id="innerDiv1_2"></div>
</div>
<div id="someDiv2">
<div id="innerDiv2_1"></div>
<div id="innerDiv2_2"></div>
</div>
</div>
If I've got the selector $('#someDiv1') in a variable -- call it $someDiv1 -- I'd like to be able to use that variable to get a string that is:
"<div id='someDiv1'>
<div id='innerDiv1_1'></div>
<div id='innerDiv1_2'></div>
</div>"
I thought about just saying $someDiv1.parent().html(), but that would give me the div's sibling(s) as well (someDiv2, etc..). Any ideas? Thanks.
You also try
$('#parentDiv').clone().find("> :not(#someDiv1)").remove().end().html();
You can try something like this:
$('<div></div>').append($('#someDiv1').clone()).html()