getContentId from title

Hi

Warning: I’m pretty new to Enonic 4.7

When you add content to different environments: dev, test, qa, stage, prod…
The content typically end up with different ids.

Now I’m assuming its not allowed to have content with the same title, same content-type in the same folder, so:

In xsl I would like to be able to get content id based on path, title, content-type.

Would it be possible to have this added to the stk library?

That would make it possible to avoid using static resources.

And avoid having to hardcode, or manually add ids as parameter, or template datasource and so on…

Hi,

We don’t have a getContentId(title). But when you get a content you’ll always find the id as the attribute @key in the current content node in the result XML. Check it out using ICE mode from admin (click “open in ICE” when viewing a menuitem).

Does this help?

The advanced search under dashboard does though. It would be nice with the same functionality available in xsl.

The content I’m talking about will be used on every page across several sites.
So I guess I would have to make a menu-item on each site and publish the content under there.

Then in the default template how do I get the published content?

I couldn’t really find anything here:
https://enonic.com/docs/4.7/xslt-functions.html
https://enonic.com/stk/template-reference/xslt

If you’re not even getting the current content out you need to set up a DataSource. It’s needed to ask the database things. “getContent” is a datasource we use when you open an article. If you open a menuitem with multiple published contents (no, you don’t need one menuitem per content) you use “getContentBySection” to extract them all. And then in your XSLT you loop through all the contents/content-nodes in the XML and manipulate the data for output.

Yeah I have to add the published content to all the page-templates via datasource, on all the sites, and all over again when “deploying”.

Not used to thinking CMS. Ruby on rails programmer here :smile:

So, you have the XML with the content? Try using the “Open in ICE” and use that little gray box you get to see the result XML that Enonic sends. By exploring this you will better know how to write your XSLT and xpaths.

The “result”-node is the big wrapping node, the main node. In there we have “context” for “Where am I and what settings do I have”-stuff. The “contents” node contain all your contents! Check it out =) And at last there is “relatedcontents” that groups any related data, such as other content, images, etc.