Customize RSS dashlet alfresco - feed.utils.ftl - alfresco

I'm new to freemarker.
I wan't to add more options in the config of the RSS dashlet and use it's value to decide if for example the title of an RSS item should be hidden.
I've found the file feed.utils.ftl which is responsible to show the title.
<#macro renderItem item target="_self">
<div class="headline">
<#if item.image??>
<img align="left" src="${item.image}" alt="" style="padding-right:10px"/>
</#if>
<h4>
<#if (item.link?exists)>
${item.title}
<#else>
${item.title}
</#if>
</h4>
<p>${item.description}</p>
<#if item.attachment??>
<div><img src="${url.context}/res/images/filetypes32/${item.attachment.type}.gif"/>${item.attachment.name}</div>
</#if>
<br />
</div>
</#macro>
There's a corresponding js file, feed.utils.js. I thought I could pass an argument from there to the ftl, for example "model.showTitle". But it has no effect.
The ftl is actively using properties of "item" so I thought maybe I can add my own property to it, but I'm unable to find where these objects are passed to the ftl. Is the macro used to include these?

If you look in share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashlets you'll find the web script files that implement the RSS dashlet. They are the files that start with rssfeed.
The rssfeed.get.js file is the server-side JavaScript controller for the dashlet.
If you were to add a line in that script's main function to set model.showTitle, you could access that value from the script's freemarker template.
The freemarker file that implements the dashlet is rssfeed.get.html.ftl.
One way to properly override either of these files is to copy them to web-extension and then the exact same package structure below that. Then you can make whatever changes you want without worrying about problems caused by changing the files distributed with Alfresco.
The latest, best approach would be to create a Share Module extension and override the files as part of that, but the copy-and-change approach to overriding is easiest.

Related

How do you include a custom component resource into an AEM Social Communities handlebars template?

In AEM 6.2, I want to do this in handlebars.
<sly data-sly-resource="${'title' # resourceType='myproject/components/content/common/title'}"/>
Specifically, I overlaid the qnaforum.hbs and need to include it in there. The official documentation(link) says the correct way to do this is:
{{include this.id path="title" resourceType="myproject/components/content/common/title"}}
When done this way there are three problems:
The component appears, but then disappears from the page.
I get the warning "Forcing resource type is not supported when sling including on the client side"
There is a failed(404) GET request to http://localhost:4502/content/myproject/qna-index-page/jcr:content/qna-parsys/qna/title.html in the browser console (like it's trying to find the renderer for the title resource at that path).
In the same qnaforum.hbs file, Adobe is using the same include for their subscriptions component and it seems to work fine.
{{include this.id path="subscriptions" resourceType="/libs/social/subscriptions/components/hbs/subscriptions"}}
Does this type of include only work for Social Communities components? If so, how can I include a custom resource in the handlebars template?
I helped some one else who was facing a similar issue. I am attaching the code snippet that caused the issue you are facing (disappearing QnA list), and the fix for that.
The overlaid QnAForum component looked like this
{{include this.id path="qnaforum-top" resourceType="custom/components/modules/qnaforum-top"}}
{{#if-wcm-mode mode="EDIT" }}
<div class="scf-includeClientLib">{{includeClientLib js="cq.social.commons.widgets, cq.social.toggle"}}</div>
{{/if-wcm-mode}}
<div data-module="qna-index" class="scf scf-forum scf-qna " data-component-id="{{id}}" data-scf-component="social/qna/components/hbs/qnaforum">
{{!-- Other QnA code --}}
</div>
But code should be like this
{{#if-wcm-mode mode="EDIT" }}
<div class="scf-includeClientLib">{{includeClientLib js="cq.social.commons.widgets, cq.social.toggle"}}</div>
{{/if-wcm-mode}}
<div data-module="qna-index" class="scf scf-forum scf-qna " data-component-id="{{id}}" data-scf-component="social/qna/components/hbs/qnaforum">
{{!-- moving line1 from previous code snippet inside this parent div}}
{{include this.id path="qnaforum-top" resourceType="custom/components/modules/qnaforum-top"}}
{{!-- rest of QnA Code }}
</div>
The change I made is, moving line1 in first code snippet into line 5.
The JS console does say missing HTML, but it gets included though. The reason for console error is the way include works.We try to fetch the html, and if we fail in fetching the HTML, we ask to sling to resolve the component.

How to use assemble to add a directory of markdown files to my index

I'm trying to add static site generation to a site in order to make it more organised and easier to contribute to. The index file has a section with with an unordered list and a number of list items that all share the same formatting. I would like to dynamically load these list items from a folder of markdown files.
I'm trying to do something like
{{forEach file in the folder}}
<li>
<div class="container">
<div class="display">
{{markdown content of the file}}
</div>
<div class="code">
<pre>
<code class="language-javascript">
{{ string from YFM in markdown file }}
</code>
</pre>
</div>
</div>
</li>
{{/forEach}}
I don't actually want each markdown file to be assembled into it's own page in my dist folder, just used as a dynamic collection of partials for my index file.
Is this possible?
These two parts of an apparently never finished tutorial explain how to use markdown files as a dynamic collection of partials to integrate on the index site:
http://www.andismith.com/blog/2014/02/getting-started-with-assemble/
http://www.andismith.com/blog/2014/02/creating-a-list-of-posts-in-assemble/
Inside the loop that's iterating the md files I used this construct to get the yfm-stripped content "included" as content on the index site (took me quite a while to figure out):
{{#markdown}}
{{page}}
{{/markdown}}
Also refer to the documentation on Collections on http://assemble.io, but careful, there's some conflicting information out there as to the options hash for collections (name: posts vs. name: post, that is, singular vs. plural and autoinflection vs. inflection: post, but bottom line: stick with the variant in the links above :))

How to get absolute file system path to an image Symfony2/Twig

I am using Symfony2 with twig to generate HTML, however the HTML I am generating is not intended for a web browser, instead it will be passed to a library that converts HTML to a PDF document.
There are two related issues I am facing.
Issue 1. This PDF will have images included, I don't want these images to be visible directly from the internet (e.g. I don’t want these images to appear under webroot). Usually I put assets in “site/src/path-to-bundle/Resources/public/assets” however, I don't want this image to be visible on the web. Can anyone suggest a good folder to put “assets” in that are not meant to be accessible via the web. (Just trying to be consistent with Symfony2 naming techniques and how other programmers would usually do this)
Issue 2. Since the HTML I am generating is intended for the HTML to PDF generator, it is most practical to refer to images with absolute paths on the file system (web paths or URLs are not suitable in this situation).
For example
<!-- This is the correct HTML code that is needed in this situation -->
<img src="/home/user/absoulte-file-system-path-to/image.png" />
<!-- These are actually incorrect in this situation -->
<img src="assets/image.png" />
<img src="http://www.somedomain.com/assets/image.png" />
I would like to know how to get the absolute path to the image mentioned above (I don’t mind if this is done in the Twig template or in the controller)
in you app/config/config.yml
twig:
globals:
root_path: %kernel.root_dir%
and you can refer to asset with relative path to your root project
<img src="{{ root_path }}/../secret-folder/image.png" />

Umbraco css vs images path

I creating new website using Umbraco(version 6.1.1 with razor) and I am new to Umbraco. My settings panel is like this.
In my Master template I am using my css styling and JavaScripts are like this. And their paths are ok.
<link rel="stylesheet" href="/css/mobile.css"/>
<script src="/scripts/jquery-2.0.2.js"></script>
CSS and scripts path are working. So that's ok.
Now my problem is I want images for my site. I don't know where to put images and what should be the path.
For example:
I tried to upload pictures to Media
In my Master template I tried
<img src="/media/A.jpg" alt="Smiley face" height="42" width="42">
<img src="/media/images/A.jpg" alt="Smiley face" height="42" width="42">
Also in the CSS file
background-image:url('/media/images/A.jpg');
But these are not working. I just trialing them. Actually I don't know the correct way of doing it :(
So where should I store images in Umbraco and how should I locate the path in CSS files and template files ?
Please help!
Thanks in Advance ....
Items stored in the media section will have a path like:
/media/<row_id>/filename.ext
Where <row_id> is literally the id of the row in the database where the media item's information is stored.
One way you can determine the path of the media item is to click on the thumbnail (if it's an image) and copy what is in the address bar.
You can also access the file by id via a macro using xslt or razor. Here's a razor example:
#{
int imageId = 1069;
var media = Library.MediaById(imageId);
<img src="#media.umbracoFile" alt="" />
}
However, this is a content management system, and you will no doubt have end-users managing the content and, therefore, it wouldn't make sense to place design specific images in the media section. A more full-proof approach would be to simply place them in an images folder in the root of your site and use them from there.
Should be as simple as this on your css:
.style { background-image: url(/media/1006530/A.jpg); }
The path you get from the media url with row id (e.g.1006530) in it

Magento templates, changing class names

I'm not sure if this is the best forum to ask this in, but I need to style a magento theme and I'm just wondering how dependent is the javascript on the class names?
For example, I have something like this in my template file (inside my theme file, overriding the base)
<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-validate-detail">
<div class="block-content">
<div class="form-subscribe-header">
If I say, leave the ids alone, but change the class names to something else (i.e. remove "block content" or "form-subscribe-header") will this break the javascript in Magento?
Also, is there an easy way to tell if I've broken something? Will I just get a console error if a piece of javascript was coupled with a css class name?
Search your javascript files for your class names to see if they are used by the script. You could also just leave your classes as they are but add a new one in, like this:
<div class="form-subscribe-header new-class">
Then target the class using .new-class
And yes, any javascript errors will appear in the console.

Resources