• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Get Page Info

New Here ,
Feb 18, 2016 Feb 18, 2016

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!

TOPICS
Newbie Corner

Views

808

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 19, 2016 Feb 19, 2016

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

...

Votes

Translate

Translate
Contributor ,
Feb 19, 2016 Feb 19, 2016

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 19, 2016 Feb 19, 2016

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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2016 Feb 21, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 21, 2016 Feb 21, 2016

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2016 Feb 22, 2016

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2016 Feb 22, 2016

Copy link to clipboard

Copied

LATEST

Well your going page for that when you should be doing that within the scope of the template. Your over complicating that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines