I want to use the if statement to select specific pages that have <body class="section-category"> and output custom content for only those pages.
My PHP is not very good and I hope this is a very simple task to do. Can anyone give me a tip?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It sounds like you want a flag available for certain pages; one that you can read out and act upon in your theme.
In template.php:
Then in your page.tpl.php
That way you keep logic where it belongs: in the preprocessors. And you keep logic out of the template, where it most certainly does not belong!
The
if (stripos($vars['foo-bar'], 'section')) {can most probably be made a lot smarter, if you do avar_dump($vars)there, all available variables will dump on your screen (browser). I am certain you will find a variable that you can check against, and that is less ‘fuzzy’ then a body class. After all: that class is meant for one thing only: to serve as class in the body-tag. And not for checking if you are in some section.You have the full Drupal available there too, so you can even use any function that (e,g, the section) modules provide.