0
Welcome Guest! Login
0 items Join Now

Particle - Check if frontpage

    • V-Web's Avatar
    • V-Web
    • Rocketeer
    • Posts: 91
    • Thanks: 0

    Particle - Check if frontpage

    Posted 5 years 11 months ago
    • What is the best way to check if a particle is active on the frontpage. I know Drupal has an option {% if is_front %}. How can this be done in G5?
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13481
    • Web Designer/Developer

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • 1. Look on the layout of the outline that is being used for the front page.
      2. Look at the "home" menu item in joomla menu manager and click on "modules" tab and look what modules are assigned to that menu item.

      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
    • V-Web's Avatar
    • V-Web
    • Rocketeer
    • Posts: 91
    • Thanks: 0

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • Hi Mr T,

      Let me rephrase; how can I programmaticaly check if the particle is active on the homepage. I have two layouts in my html.twig file. One that is only used on the homepage, another that is used on all other pages. So I need to check if the current URL is the homepage and if so I need to use "Layout 1", otherwise "Layout 2".

      I've been trying things with "gantry.page.url()" (which returns the entire URL), "gantry.siteUrl()" (which returns /). Now these both give me the information I need but I can't put it in my if statement as it will never match.
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13481
    • Web Designer/Developer

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • Why can't you just put the "layout type" as a yaml field and then configure the instance on the "home" page to use "layout1" and the instances on other pages to use "layout2". Then it's just a check of the yaml field in your twig file. Alternately you could actually programatically get the outline ID and/or menu item id - but I think this would be the wrong approach because you would be hardcoding variables into your TWIG code that are unique to your specific site and which may change.

      This will help though if you do take the latter approach http://docs.gantry.org/gantry5/advanced/creating-a-new-particle#pulling-gantry-configuration-data-using-twig . Use the Gantry 5 debugbar to find the correct variable name.

      Regards, Mark.
    • Last Edit: 5 years 11 months ago by MrT.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
    • V-Web's Avatar
    • V-Web
    • Rocketeer
    • Posts: 91
    • Thanks: 0

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • Basically we're using only one instance of the particle on two pages. One on the homepage and one on a different page, where we want a different layout. In my opinion a simple check if you're on the homepage would work perfectly.

      I've checked the other method as well. What I can't understand is what happens if you have multiple instances of the same particle. Which setting is then pulled in?
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13481
    • Web Designer/Developer

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • Well what you need is one instance on one page and a different instance on another page. There are two ways you can go about that.

      1. Your pages could use different outline (and therefore different instance on the layout).

      OR

      2. You could just put a "module position" particle on the layout and then have two modules (one for each Gantry 5 particle instance) assigned to the relevant menu items only.

      Really I don't think you should be hardcoding "homepage" (in whatever form that technically takes) into the TWIG code - it's the wrong thing to be doing - it's the choices you make in the particle instance that should be dictating what is used. This is the way we code every particle where there are configurable options.

      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
    • V-Web's Avatar
    • V-Web
    • Rocketeer
    • Posts: 91
    • Thanks: 0

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • Both are viable options and I probably will go for the layout option.

      But still ;). How can I check if I'm on the homepage within HTML twig? I really appreciate the solutions provided but now the question that keeps itching is how it can be done...
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13481
    • Web Designer/Developer

    Re: Particle - Check if frontpage

    Posted 5 years 11 months ago
    • MrT wrote:
      ... Alternately you could actually programatically get the outline ID and/or menu item id - but I think this would be the wrong approach because you would be hardcoding variables into your TWIG code that are unique to your specific site and which may change.

      This will help though if you do take the latter approach http://docs.gantry.org/gantry5/advanced/creating-a-new-particle#pulling-gantry-configuration-data-using-twig . Use the Gantry 5 debugbar to find the correct variable name.

      I already answered that - see above.

      Regards, Mark.
    • Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.

Time to create page: 0.044 seconds