Hey guys, how are you doing?
I'm trying to create a .txt file on my content repository everytime a specific template is used on AEM 6.0. So, I tought about put this code in a component .jsp file and then including this component on this specific template.
My two questions is: can someone give me a sample code of simply creating a .txt file somewhere in the content repository (/content/files, for example) to be used on a component?
And, is this the correct/best way to achieve what I want to achieve?
I have some idea on how to do this using a .java class, creating a new resource and all, and then calling this as a service on a component, but I believe that there has to be an easier way, like directly in the component.
Thanks very much.
Solved! Go to Solution.
Views
Replies
Total Likes
For something like that where it's associated to a site I'd make it a selector based script of the template in question rather than generating an actual text file. So you'd end up with a solution that looks something like this:
Views
Replies
Total Likes
Hi Mat.Barreto,
Better to upload such files in dam and refer in component.
Thanks,
Sham
Tweet @adobe_sham
Views
Replies
Total Likes
Could you provide a some details on what the purpose of the text file is? Generally putting code like that in a component would typically not be best practice, but where to the put the logic would depend a little on what the purpose text file is. One option is to leverage a either a JCR Observer or Sling Event to handle the file creation. You would listen for new node creations and then filter based on the node type and template value. Check out these blog posts for some of these options:
One of the complexities to consider is whether or not you need this text file to be present in the publish server, and whether or not you want to create the the text file in publish when new pages are first published, or if you want activate the text files from the author server to the publish server.
Views
Replies
Total Likes
The text file will be a robots.txt file, for SEO purposes. So, it need to be on publish server.
However, this file need to be automaticaly created everytime the user creates a new site using the, for example, "Home with robot" template.
Is there a better way to achieve this?
Views
Replies
Total Likes
Hi Sham,
Thanks for the replying, but in my case the files need to be created dynamicaly, everytime a new page is created using one specific template, in a specific and diferent path everytime.
So, it can't be a existing file.
Views
Replies
Total Likes
Ok. What is the plan with that text file? When will you render it on that page. If i understand usecase correctly can we achieved using oob text or image component along with cq:template. Image component can render image from both dam and locally. With this you have file stored at page level only. High level idea is [1].
[1] http://blogs.adobe.com/experiencedelivers/experience-management/defaults-in-your-component/
Views
Replies
Total Likes
For something like that where it's associated to a site I'd make it a selector based script of the template in question rather than generating an actual text file. So you'd end up with a solution that looks something like this:
Views
Replies
Total Likes
Mat.Barreto wrote...
The text file will be a robots.txt file, for SEO purposes. So, it need to be on publish server.
However, this file need to be automaticaly created everytime the user creates a new site using the, for example, "Home with robot" template.
Is there a better way to achieve this?
http://adobe-consulting-services.github.io/acs-aem-commons/features/simple-sitemap.html
Views
Replies
Total Likes
Orotas, thanks for the response.
This probably works, I've already used a similar approach to generate json content, however, as an selector based script, someone someday has to access an url with the selector to trigger the creation of the file, right?
There is no way to get one template to automatically create a file in the JCR when someone assign a page to it?
Views
Replies
Total Likes
Views
Likes
Replies