Code Monkey home page Code Monkey logo

joomla-twig's People

Contributors

brianteeman avatar c-lodder avatar phproberto avatar zero-24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

joomla-twig's Issues

how to pass data from component to the parent view

Hi,
I've been struggeling with this for a while.

I'm used to Twig and its inheritance thru blocks outside of this Joomla enviroment.
But the blocks in joomla has no power over the joomla native inheritance in many cases.

In a nutshell:
Say we have index.php in the template root where the $this includes many data but the article content which is available in the <jdoc:include type="component" /> and not in its parent view.

specifically:
the index.php loads a article.html.twig that extends base.html.twig..
The article.html.twig is populated by needed data from the index php like so:

$data = array(
	'sitename' => htmlspecialchars($app->get('sitename'), ENT_QUOTES, 'UTF-8'),
	'site_url' => JUri::base(),
..

That is all fine we can play with the data we prepared in the main index.php
The data by the Joomla nature does not have the article data yet. They are loaded as part of the "component". One might think we can make a block placeholder and fill it up from the child component view. But that does not work here.
It is a bit of a problem as if we for example want to load extra_fields from the com_k2 outside its own view we are out of luck.. or at least I am. As I still heaven't found how to send share data from child view to parent view.

It would be awesome to have something like jmodule_get_module for components. That will allow us to get the component data as such and play with the dat in their raw form anyway we like in any time and place we like.
Hope I'm understood a bit.

Trait to use joomla-twig as component view renderer.

Main ideas:

  • Any view can use twig renderer with something like: use Phproberto\Joomla\Twig\Traits\ViewTwigRenderer;
  • Additionally we need to move all the logic to load data (done in display() methods) to a getLayoutData().
  • Trait will require views to implement getLayoutData() (which is also a good practice) and override the loadTemplate logic so it doesn't need any extra changes by users.
  • Consider the option to put the twig render call inside the old php layout so system is 100% compatible. If use has overriden the layout the twig call is never done.

Example com_users/views/login/tmpl/default.php content would be something like:

echo Twig::render('@component/com_users/login/default.html.twig', $this->layoutData);

So if user has an override the legacy rendering will be used.

Maybe a pure twig rendering + a legacy mode.... play with it.

Add information about debug

User reported this:

I wanted to give you some feedback on something I found when first trying to use Joomla-twig.
On the main github page under Installation it says you can do this to view an example:

JLoader::import('twig.library');
echo Twig::render('@library/twig/examples.html.twig');

When I tried this I received an error because dump() couldn’t be found. I had to use this code to get the example to work:

JLoader::import('twig.library');
$twig = Twig::instance();
$twig->environment()->addExtension(new Twig_Extension_Debug());
$twig->environment()->enableDebug();
echo Twig::render('@library/twig/layouts/examples.html.twig');

After I had that working I had a lot more confidence in using your project.

Add information about how to use debug and how it works in default mode.

joomla-twig-debug-auto

missing white spaces PHP 7.4

Hi

For anyone suffering.
If you update to PHP7.4 twig like:
{{ something }} {{ else }}
will become "somethingelse" instead of expected "something else"

solution:
update twig to 2.14.4
go to extensions/libraries/composer.json

update require twig version to
..
"twig/twig": "~2.14.4",
..

run "composer update" in library folder
..nightmare is gone.. I mean partially

Introduce JForm?

Check if it makes sense to provide a jform function to load a form

Class 'Twig\Loader\ChainLoader' not found

Hi! I've just installed the latest package of the plugin in Joomla. I followed the instruction for testing but I received this error message:
Class 'Twig\Loader\ChainLoader' not found
I've checked in all files and i cannot find any class named ChainLoader. Could a file could be missing in the package ?
Thank you!

Incompatibility with gantry

with this simple code :

JLoader::import('twig.library');
echo Twig::render('@component/com_allevents/events/agenda.twig');

I obtain :

Warning: count(): Parameter must be an array or an object that implements Countable in /home/alleve87/public_html/plugins/system/gantry/gantry.php on line 406

Error: Argument 1 passed to Gantry\Component\Twig\TwigNodeTry::__construct() must be an instance of Twig_NodeInterface, instance of Twig_Node given, called in /home/alleve87/public_html/libraries/gantry5/classes/Gantry/Component/Twig/TokenParserTry.php on line 49: Argument 1 passed to Gantry\Component\Twig\TwigNodeTry::__construct() must be an instance of Twig_NodeInterface, instance of Twig_Node given, called in /home/alleve87/public_html/libraries/gantry5/classes/Gantry/Component/Twig/TokenParserTry.php on line 49

Of course I use a Gantry template :)

Do you have any idea ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.