id or slug of current page in template.php

  • Hi,


    I'm trying to modify a template to dynamically add a html-class to a position-div in template.php.


    The class name should contain the id or slug of the current page.


    For example:

    When page "home" is rendered, class "main-home" should be added,

    when page "contact" is rendered, class "main-contact".


    Is there a way to get the current page id or slug out of the $view-object in template.php? Or another way?


    Thanks!

  • SPQRInc

    Approved the thread.
  • Hi Uuumpf,


    yes, app is provided as variable to the template, so this should be possible. As an alternative you can also register a callback for the view.init event and provide the information as global directly there. Then you can access it also using the variable name you want to use. The app and view variables are added using this approach here: https://github.com/pagekit/pag…dules/view/index.php#L140


    Best regards,

    Tobbe