Copy link to clipboard
Copied
With {module_pagename} you get the pagename of the current page you visit.
Is there also a way to get the template ID of the page you currently visiting with module or any liquid tags?
Thanks!
The OID position placement will differ per site based on the call, naming you collections is also important for good use in your projects.
{module_pagename} can be set as a data element to say your body tag so it does not render in your actual website.
From there, this is now accessible as a liquid data point.
{{pagename.name}} To get:
{module_data resource="pages" version="v3" fields="id,templateId,name" where="\{'name':'{{pagename.name}}'\}" skip="0" limit="2" order="id" collection="pageData"}
{{p
...Copy link to clipboard
Copied
Hi,
You can get this with liquid:
<p>PageID: {{oid_0.oid}}</p>
<p>Page Name: {module_pagename}</p>
{module_data resource="pages" version="v3" fields="id,templateId,name,template" resourceId="{{oid_0.oid}}" order="id" collection="myData"}
<p>Template ID: {{myData.templateId}}</p>
<p>Template: {{myData.template.name}}</p>
Copy link to clipboard
Copied
The OID position placement will differ per site based on the call, naming you collections is also important for good use in your projects.
{module_pagename} can be set as a data element to say your body tag so it does not render in your actual website.
From there, this is now accessible as a liquid data point.
{{pagename.name}} To get:
{module_data resource="pages" version="v3" fields="id,templateId,name" where="\{'name':'{{pagename.name}}'\}" skip="0" limit="2" order="id" collection="pageData"}
{{pageData.templateId}
That is a bit cleaner and more reliable.
I have a couple of other posts with people thinking the template id could be useful for their liquid conditions. But it really is not though. You can not control templates on the front end, you can not dynamically change them. One page can only have one template.
I see the thinking, but far other better options and ways to achieve things.
Copy link to clipboard
Copied
Yes this approach works for pages.
The only downside is when system generated pages like, blog,faq,system pages, webapps. even those have different template assigned.
I currently have now idea how to get the template Id if l landed on those system pages.
Any ideas?
Copy link to clipboard
Copied
Possible, but just a lot of work and code on the layouts you have access too.
Can I ask why? What are you trying to achieve? Like I said, I bet you do not need to do this.
Copy link to clipboard
Copied
Thank you for your reply.
Currently I want to fully use the abilities of liquid and try to avoid javascript as much as possible.
Currently I want those pages with certain type of template to display different content.
{% if {{myTemplate}} == 'templateIDA' -%}
{module_contentholderA}
{% endif %}
{% if {{myTemplate}} == 'templateIDB' -%}
{module_contentholderB}
{% endif %}
Hope it is not too complex to achieve this. Or maybe other suggestions?
Thank for your time!
Copy link to clipboard
Copied
Well your going page for that when you should be doing that within the scope of the template. Your over complicating that.