This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

finky458574
finky458574

I have a header that has view logic dependent on what page or layout is currently being displayed. Basically I need an if statement based on current layout or page. How do I access these variables?

Alternatively and preferably: I find Twig to be a pain in the butt as it restricts anything that I want to do and have to create special functionality. I am a single developer and I don't have someone non-technical editing and creating the views. Is there a way to disable Twig or enable pure PHP in views? Please don't bother telling me why Twig is better, I just want to finish my site, not get into a debate.

finky458574
finky458574

This place is dead. If October CMS wants to grow maybe those who care about it should spend more time building better documentation and helping those trying to adopt it. Meanwhile I'm going to find another more mature and better CMS and probably never look back.

pratyushpundir6424
pratyushpundir6424

Hi there,

Just in case you're still interested.

You can access these page related variables like so (you may not like it but this uses Twig):

Example - Echo the layout name

{{ this.page.layout }}

Example - Echo the url for this page

{{ this.page.url }}

Example - Using 'if statement' in Twig

{% if this.page.url == '/something' %}
    . . . Do something here
{% endif %}

I haven't yet explored disabling Twig completely but I do sometimes feel like what you're saying. Also, I agree with the need for there being better documentation. Honest opinion though, I have started to really like the MV** approach. It's kinda making me look at everything with much more of "Reusability" in mind. Though I think the trick sometimes will be to balance out code-reuse with complexity. So far, I've been enjoying it. Sure there were tons of glitches but I like the approach and I think I'll stick with this for a tad bit longer.

I want to see what it is after it is officially released or at least out of RC.

Krisawzm
Krisawzm

Just fyi finky458574, what pratyushpundir6424 is referencing is perfectly documented in Documenation > Markup guide. Maybe if you had bothered to actually read the documentation, you wouldn't have needed to get so upset. Stress isn't good for your body I've heard.

Anyway, this.page.url doesn't exist. You should probably use this.page.id:

If the page file was home/index.htm this would generate a class name of page-home-index.

Alternatively, you could use this.page.fileName or this.page.baseFileName (see the Documentation)

Next time, maybe be a little more patient? You could also check out the IRC chat which might yield quicker response. :-)

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.