Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get current view in page_head.html.twig #3295

Closed
lipatovroman opened this issue Jan 7, 2025 · 2 comments
Closed

How to get current view in page_head.html.twig #3295

lipatovroman opened this issue Jan 7, 2025 · 2 comments

Comments

@lipatovroman
Copy link

Hello!
How get current view in page_head.html.twig?
I need to add some code depending in current view - article or category.

@lipatovroman
Copy link
Author

lipatovroman commented Jan 7, 2025

I've tried this:
{% set current_url = joomla.call('JUri::current') %}

{{current_url}}

and it's working.

I've tried this code - and it doesn't work:
{% set view = joomla.call('JFactory::getApplication().input.get', 'view') %}

{{ view }}

@lipatovroman
Copy link
Author

Strangely, nothing is said about this in the Gantry5 documentation.
I spent more than 2 hours with ChatGPT - but he could not help me.
But today I got lucky with Claude - he completed the task perfectly. The only thing is that I still couldn't get the home page.

So:

{% set app = joomla.call('JFactory::getApplication') %}
{% set input = app.input %}
{% set menu = app.getMenu() %}
{% set active = menu.getActive() %}

{% set current_view = input.get('view') %}
{% set itemId = input.get('Itemid') %}
{% set isHome = menu.getDefault().id == active.id %}
{% set option = input.get('option') %}
{% set articleId = input.getInt('id') %}

View: {{current_view}}
Menu Item ID: {{itemId}}
Is Home: {{isHome}}
Component: {{option}}
Article ID: {{articleId}}

And another way

{% set current_view = joomla.call('JFactory::getApplication').input.get('view') %}
{% set current_option = joomla.call('JFactory::getApplication').input.get('option') %}
{% set current_id = joomla.call('JFactory::getApplication').input.get('id') %}
{% set current_itemid = joomla.call('JFactory::getApplication').input.get('Itemid') %}

{% set menu = joomla.call('JFactory::getApplication').getMenu() %}
{% set active = menu.getActive() %}
{% set default = menu.getDefault() %}
{% set is_home = (active and default and active.id == default.id) %}

View: {{current_view}}
Option: {{current_option}}
ID: {{current_id}}
Menu Item ID: {{current_itemid}}
Is Home: {{is_home}}

In both cases Is Home does not work.

Before making any changes in

/media/gantry5/engines/nucleus/templates/page_head.html.twig
/media/gantry5/engines/nucleus/templates/page.html.twig

need to override them in

/templates/your-template/custom/engine/templates/page_head.html.twig
/templates/your-template/custom/engine/templates/page.html.twig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant