How to list all siteItem in a component folder in a ftl template? - crafter-cms

In Crafter CMS, I have a list of components under a folder in "Components".
So the structure is:
/site/components/folder1/component1.xml
/site/components/folder1/component2.xml
...
So what I am trying to do is to list these components and display them in my Crafter site
I have tried this:
<#list siteItemService.getSiteItem("site/components/folder1").getChildItems() ! [] as item>
<p>${item.title_s}</p>
</#list>
But it does not work.
Does anyone has an idea of how to do this?

Ok so I used getSiteTree("/site/components/folder1", 1).getChildItems() instead and now it is working.
It did not found it in the documentation (https://javadoc.craftercms.org/3.0.27/engine/org/craftercms/engine/model/SiteItem.html).

Related

Cloning Shopware 6 CMS Element

Shopware 6 | Cloning CmsElement and get null as data,
and in the Shopware 6 Forum: https://forum.shopware.com/discussion/67124/custom-product-box-no-data-in-the-storefront
I found this answer, but as I am still learning Shopware 6, I don't know if this is relevant for me. I have cloned the CMS Product Box Element, as I need to change the layout and add more flags/badges, but when I do a dump I get element.data = null. Would I also need to create a resolver too, or should I have just tried to extend the element with {% sw_extends '#Storefront/storefront/element/cms-element-product-box.html.twig' %}? But if I just extend I can't make the changes I want to the component.
Any suggestions or hints on how to solve the problem would be appreciated. Thanks.
I figured out it was much simpler than creating a new element. In the end, I found which components were being included and found that to change the layout and add a new badge I just needed to {% sw_extends '#Storefront/storefront/component/product/card/badges.html.twig' %} and for the parts of the product-box, just find the corresponding component and make the changes I needed to make in my plugin.

Liferay, Freemarker error template from search but not from other link

Using liferay 7 GA4 and freemarker engine.
We encountered a strange behaviour with the freemarker engine.
We have a bunch of web contents using all the same .ftl template.
Here is the begining of the template:
<#assign journalArticleId = .vars['reserved-article-id'].data>
<#assign journalArticleResourceLocalServiceUtil =
staticUtil["com.liferay.journal.service.JournalArticleResourceLocalServiceUtil"]>
<#assign assetCategoryLocalServiceUtil = staticUtil["com.liferay.asset.kernel.service.AssetCategoryLocalServiceUtil"]>
<#assign articleResourcePK = journalArticleResourceLocalServiceUtil.getArticleResourcePrimKey(groupId, journalArticleId)/>
<#assign categories = assetCategoryLocalServiceUtil.getCategories("com.liferay.journal.model.JournalArticle",articleResourcePK) >
<#list categories as category>
<#if category?is_first>
<#assign categorie = category.getName()>
</#if>
</#list>
<#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()>
<#assign themeDisplay = serviceContext.getThemeDisplay() />
<#assign currentUrl = themeDisplay.getPortalURL() + themeDisplay.getURLCurrent() />
And here is the error :
Error
On a public page we have an asset publisher listing all these web contents.
When clicking on one of these everything is fine and the web content is correctly rendered.
Now if we search for this web content via the search portlet, it's also correctly rendered.
The problem is : if we decide to search for the web content before using the asset publisher, the freemarker engine is not able to deal with the template.
In fact we got this kind of error.
The best part is that after you get the error via search, you still can't display it via the asset publisher. Everything is finally broken in that case.
I sincerely think that we tried every solution regarding freemarker engine (portal-ext.properties, freemarker allowed/restricted class etc).
I can't understand why if we come from any other page that can display these web contents it's working fine, but not at all if we search for it at strat.
Thanks for you help everybody.
Edited with template and error
Edit #2 : Here is the error when switching to serviceLocator :
serviceLocatorError
You don't need staticUtil to retrieve the DLFileEntryLocalServiceUtil, try to use the serviceLocator instead:
<#assign DLFileEntryLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>
NB.
You had to enable the serviceLocator in your templates:
Go to Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables and remove serviceLocator then restart Liferay.

Liferay embedding web content into another webcontent

Is it possible to embedded web content into another webcontent? For example:
Webcontent A:
...
<div class="someClass">
<!-- i want to include here the Webcontent from B -->
</div>
...
Webcontent B:
...
<div>
...
</div>
...
Any help is appreciated.
To answer your question straight:
Plain Webcontent can't do this, but if you create a custom structure which contains an id of the embedded article (as well as the other text) you can do this. Structures and Templates are a feature of Liferay's Webcontent: Instead of a plain HTML rich text elements, you can build your article from many structured elements. Then you create a template which combines all these elements into the output HTML. In those template you can process the output and - to limited extent - access Liferay's API to load other articles.
To answer your question in a roundabout way:
I can't imagine any underlying problem that I'd solve this way. Thus I'm assuming that there is a better solution to your (underlying, but unknown to me) problem.

Override part template Orchard

I starting with orchard. I want to override MenuWidgetPart to render as i want. I've created Parts.MenuWidget-MenuWidget.cshtml into Views folder of current theme. But i do not know, how to i can get list menu from Model. Please look my code below:
<nav>
<ul>
#foreach(var m in listMenu){
<li>#m.Text</li>
}
</ul>
</nav>
How to i can get listMenu from Model ?
Templates for Menu and MenuItem are Menu.cshtml and MenuItem.cshtml. You can start by copying those files from /Core/Shapes/Views/ directory to your theme directory. You can modify them as you wish afterwards.
This will, actually modify all your menus on the site. If you want it to be specifically for your widget (Parts.MenuWidget-MenuWidget.cshtml) you can start by copying the contents from Menu.cshtml to your widget template and continue with modifications from there.
EDIT:
To iterate over items you can use the following syntax:
#foreach (var item in Model.Menu.Items){
#Display(item)
}

SharePoint 2007 - How To Change Attachment Paperclip Image

When a list item has an attachment, SharePoint automatically renders a paperclip image for that particular row, which indicates that the item has an attachment. Is there any way to change the image that is rendered?
The site is in a shared hosting environment, so I can't simply replace the image on the file system. Also, there are other lists that are part of the same site that should use the default image.
Is there any way to change the image that is rendered for items with an attachment on an individual list basis?
EDIT: Following is the HTML that is rendered:
<td class="ms-vb2">
<img align="absbottom" src="http://devsandbox/_layouts/images/attach.gif" alt="Attachment"/>
</td>
The only real way you'll be able to do this is to use jQuery (or some other javascript library). You'll need to locate the elements you want to update on the page and change the URL's
$('img[src*=attach.gif]').each(function() {
$(this).attr('src', '/path/to/new/image.png');
}
My jQuery may be a touch wrong but that should be near enough to give you an idea of what to do
Edit - The best way to have this down would be via a custom WebPart which renders the JavaScript. This way it can easily be dropped into any page you want
i don't know which element off the top, but I would look for it in one of the stylesheets and use SharePoint designer to do the replacement work for a specific list.
Use Firebug to inspect the element that you want to revert. This will tell you the css class and other properties used by that element. Then write your own class and add it to the core.css file or if you want, add it to the css for the Site/Site Collection through the MasterPages link in Site Settings.
EDIT
I used firebug to look at an image in SharePoint and here is how it is rendering.
<img id="img_1-2_" class="rpo-gif rpo-gif-2" border="0" style="padding: 0px;" alt="Expand/Collapse" src="/_layouts/images/minus.gif"/>
As you can see it is using a class and setting a src to '/_layouts/images/minus.gif'. Well you can go find that file in the 12Hive directory and then replace it with an image of your choice that has the same name.

Resources