gantry5
gantry5 copied to clipboard
Twig in Custom HTML Particles
I'm still learning my way around Gantry 5 and I ran across an option in the custom HTML particle that allows Gantry to process twig code in the particle. I've looked, but I can't find anything on what's allowed or even how certain attributes can be included into the particle.
So, say I want to pull in the menu item title from a menu item in Joomla into the particle, how would I do that? Sorry if this is a dumb question. I'm just not familiar with Twig and how it works with Gantry.
Allowing twig in custom html doesn't mean that you can access everything in the platform, but it does give you access on Gantry DI container and to some basic classes/functions of Joomla.
Here's short list:
{{ gantry.platform.call('pow', 2, 4) }}
{{ gantry.platform.filter('<p>my name is [[name]]. Calls content plug-ins.</p>') }}
{% set menu = joomla.factory('menu') %}
{% set me = joomla.factory('user') %}
{% set user = joomla.instance('user', 64) %}
{% set route = joomla.route('index.php?option=com_content') %}
{% do joomla.html('jquery.framework') %}
{% do joomla.html('jquery.ui', ['core']) %}
I hadn't realized that I could set things myself. That makes things easier. If I may, is there a list of everything that you can have access to via Twig in the custom HTML particle?
And before I forget, thank you for your help. :)
Edit:
Correct me if I'm wrong, but it looks like joomla.factory('menu')
would be JFactory::getApplication()->getMenu();
so, if I wanted the title of the active menu item, I'd have something like joomla.factory.menu.active('title')
or is this totally wrong.
right now there is no list, but I started to create one when you first asked about it.
All of the above should be pretty obvious; I don't think I need to give you JFactory
functions or list all Joomla classes with getInstance()
. Same is true for available PHP functions etc..
Every call also accepts the same parameters as the real functions.. All that you need to do is to just list them after the first parameter.
No, I think I can find those. ;)
Thanks for your time and help. I look forward to seeing where Gantry goes from here. It is really a lot of fun to work with.
Cc-ing @FrugalGeek for documenting this. Would be nice to get this list out of GitHub and into our docs.
Was this ever done?
+1
Its not yet documented. I decided to concentrate on some simple fixes/improvements instead.
Any update on documentation? I am very interested in being able to use {% set user = joomla.instance('user', 64) %}
But for some reason all it ever returns is the user 64, not the active logged in user. Am I missing something?
Your help is MUCH appreciated!
You are using wrong call. In Joomla you can either load a fixed userid (by using above call) or the current user by using {% set user = joomla.factory('user') %}
.
right now there is no list, but I started to create one when you first asked about it.
Is there any progress in the documentation?