The active template is {% raw %}{{ japp.getTemplate() }}{% endraw %}
20 | ```
21 |
--------------------------------------------------------------------------------
/docs/globals/jlang.md:
--------------------------------------------------------------------------------
1 | ## jlang
2 |
3 | This variable is a proxy of Factory::getLanguage(). It allows to access the active language inside twig layouts.
4 |
5 | 1. [Returns](#returns)
6 | 2. [Examples](#examples)
7 |
8 | ### Returns
9 |
10 | `Joomla\CMS\Language\Language` The active language.
11 |
12 | ### Examples
13 |
14 | ```twig
15 | {#
16 | Use active language tag inside a layout. Will print something like:
17 | Active language is en-GB
18 | #}
19 |
{% raw %}Active language is {{ jlang.getTag() }}{% endraw %}
20 | ```
21 |
--------------------------------------------------------------------------------
/tests/tests/View/Traits/Stubs/ClassWithTwigRenderer.php:
--------------------------------------------------------------------------------
1 | $this];
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 |
3 | language: php
4 |
5 | addons:
6 | sonarcloud:
7 | organization: "phproberto-github"
8 | token:
9 | secure: "$SONAR_TOKEN"
10 | branches:
11 | - develop
12 | - master
13 |
14 | jdk:
15 | - oraclejdk8
16 |
17 | cache:
18 | directories:
19 | - ./build/node_modules
20 | - $HOME/.composer/cache/files
21 | - $HOME/.sonar/cache
22 |
23 | php:
24 | - 7.0
25 | - 7.1
26 | - 7.2
27 |
28 | branches:
29 | only:
30 | - master
31 | - develop
32 |
33 | before_script:
34 | - ./ci/setup.sh
35 |
36 | script:
37 | - ./ci/test.sh
38 | - sonar-scanner
39 |
--------------------------------------------------------------------------------
/docs/globals/juser.md:
--------------------------------------------------------------------------------
1 | ## juser
2 |
3 | This variable is a proxy of Factory::getUser(). It allows to access the active user as a User object inside twig layouts.
4 |
5 | 1. [Returns](#returns)
6 | 2. [Examples](#examples)
7 |
8 | ### Returns
9 |
10 | `Joomla\CMS\User\User` The active User object.
11 |
12 | ### Examples
13 |
14 | ```twig
15 | {# Check if user is guest and say hello #}
16 | {% raw %}{% if juser.get('guest') %}{% endraw %}
17 | Hello guest!
18 | {% raw %}{% else %}{% endraw %}
19 | Hello {% raw %}{{ juser.get('name') }}{% endraw %}!
20 | {% raw %}{% endif %}{% endraw %}
21 | ```
22 |
--------------------------------------------------------------------------------
/docs/functions/jposition.md:
--------------------------------------------------------------------------------
1 | ## jposition($position, $attribs = [])
2 |
3 | It allows to render a module position inside a twig layout.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$position** Name of the position to render
12 | * `array` **$attribs** An array of attributes for the module chrome function.
13 |
14 | ### Returns
15 |
16 | `string` HTML with the position content
17 |
18 | ### Examples
19 |
20 | ```twig
21 | {% raw %}
22 | {# Render the content of the template position-8 #}
23 | {{ jposition('position-8') }}
24 | {% endraw %}
25 | ```
26 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Joomla Twig Package
5 | Twig integration for Joomla!
6 | pkg_twig
7 | package
8 | 1.5.0
9 | site
10 | https://github.com/phproberto/joomla-twig/releases/tag/v1.5.0
11 |
12 | https://github.com/phproberto/joomla-twig/releases/download/v1.5.0/joomla-twig-v1.5.0.zip
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/sonar-project.properties:
--------------------------------------------------------------------------------
1 | # must be unique in a given SonarQube instance
2 | sonar.projectKey=phproberto:joomla-twig
3 | # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
4 | sonar.projectName=joomla-twig
5 | sonar.projectVersion=1.4.0
6 |
7 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
8 | # This property is optional if sonar.modules is set.
9 | sonar.sources=./extensions/libraries/twig/src
10 |
11 | sonar.tests=./tests
12 | sonar.php.tests.reportPath=./tests/coverage/report-junit.xml
13 | sonar.php.coverage.reportPath=./tests/coverage/report-clover.xml
14 |
15 | # Encoding of the source code. Default is default system encoding
16 | sonar.sourceEncoding=UTF-8
17 |
--------------------------------------------------------------------------------
/ci/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Clone current joomla & install composer there
4 | git clone https://github.com/joomla/joomla-cms.git /tmp/joomla-cms
5 | composer install -d /tmp/joomla-cms
6 |
7 | # Install joomla-twig testing composer dependencies
8 | composer install --prefer-dist --no-interaction --no-progress
9 |
10 | # Install joomla-twig library composer dependencies
11 | composer install -d ./extensions/libraries/twig
12 |
13 | # Copy CI gulp config (with cloned joomla path) to the build folder
14 | cp ./ci/gulp-config.ci.json ./build/gulp-config.json
15 |
16 | # Install npm packages in the build folder
17 | cd ./build
18 | npm install -g gulp
19 | npm install
20 |
21 | # Copy joomla extensions to the cloned joomla site
22 | gulp copy
23 | cd ..
24 |
--------------------------------------------------------------------------------
/docs/functions/jlang.md:
--------------------------------------------------------------------------------
1 | ## jlang($key = null, $debug = false)
2 |
3 | This function is a proxy of `Language::getInstance()`. It allows to access HTML drawing classes inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$lang** [optional] The language to use. Default: `en-GB`
12 | * `boolean` **$debug** [optional] The debug mode. Default: `false`
13 |
14 | ### Returns
15 |
16 | `\Joomla\CMS\Language\Language` Language object
17 |
18 | ### Examples
19 |
20 | ```twig
21 | {% raw %}
22 | {# Show the spanish language name #}
23 | {{ jlang('es-ES').getName() }}
24 | {% endraw %}
25 | ```
26 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "phproberto/joomla-twig",
3 | "type": "library",
4 | "description": "Twig integration for joomla",
5 | "keywords": ["joomla", "twig"],
6 | "homepage": "https://github.com/phproberto/joomla-twig",
7 | "license": "GPL-2.0",
8 | "authors": [
9 | {
10 | "name": "Roberto Segura",
11 | "email": "roberto@phproberto.com",
12 | "homepage": "http://www.phproberto.com"
13 | }
14 | ],
15 | "require" : {
16 | "php": "^7.0",
17 | "twig/twig": "~2.0",
18 | "twig/extensions": "^1.4"
19 | },
20 | "autoload": {
21 | "psr-4": {
22 | "Phproberto\\Joomla\\Twig\\": "src/"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/japp/japp.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JAPP
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JAPP_DESC
12 |
13 | language
14 | japp.php
15 | japp.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jdoc/jdoc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JDOC
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JDOC_DESC
12 |
13 | language
14 | jdoc.php
15 | jdoc.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/juri/juri.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JURI
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JURI_DESC
12 |
13 | language
14 | juri.php
15 | juri.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jhtml/jhtml.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JHTML
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JHTML_DESC
12 |
13 | language
14 | jhtml.php
15 | jhtml.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jlang/jlang.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JLANG
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JLANG_DESC
12 |
13 | language
14 | jlang.php
15 | jlang.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jtext/jtext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JTEXT
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JTEXT_DESC
12 |
13 | language
14 | jtext.php
15 | jtext.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/juser/juser.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JUSER
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JUSER_DESC
12 |
13 | language
14 | juser.php
15 | juser.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/docs/functions/jmodule_render_module.md:
--------------------------------------------------------------------------------
1 | ## jmodule_render_module($module, $attribs = array())
2 |
3 | Render a module object.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `object` **$module** Object containing module information
12 | * `array` **$attribs** [optional] Array of attributes for the module (probably from the XML).
13 |
14 | ### Returns
15 |
16 | `\string` Rendered module.
17 |
18 | ### Examples
19 |
20 | ```twig
21 | {% raw %}
22 | {# Retrieve and display all the modules in a sidebar position #}
23 | {% for module in jmodule_get_modules('sidebar') %}
24 | {{ jmodule_render_module(module) }}
25 | {% endfor %}
26 |
27 | {% endraw %}
28 | ```
29 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jarray/jarray.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JARRAY
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JARRAY_DESC
12 |
13 | language
14 | jarray.php
15 | jarray.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jroute/jroute.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JROUTE
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JROUTE_DESC
12 |
13 | language
14 | jroute.php
15 | jroute.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jlayout/jlayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JLAYOUT
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JLAYOUT_DESC
12 |
13 | language
14 | jlayout.php
15 | jlayout.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jmodule/jmodule.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JMODULE
4 | 1.0.0
5 | June 2018
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JMODULE_DESC
12 |
13 | language
14 | jmodule.php
15 | jmodule.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/View/ItemFormView.php:
--------------------------------------------------------------------------------
1 | $this->getModel()->getForm()
34 | ]
35 | );
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/docs/functions/jmodule_get_modules.md:
--------------------------------------------------------------------------------
1 | ## jmodule_get_modules($position)
2 |
3 | Gets modules assigned to a specific position.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$position** Name of the position
12 |
13 | ### Returns
14 |
15 | `array` An array containing modules of that position. Empty array if no modules were found.
16 |
17 | ### Examples
18 |
19 | ```twig
20 | {% raw %}
21 | {# Retrieve modules available in a `sidebar` position #}
22 | {% set modules = jmodule_get_modules('sidebar') %}
23 | {% for module in modules %}
24 |
Found module: {{ module.name }} with title: {{ module.title }}
25 | {% endfor %}
26 |
27 | {% endraw %}
28 | ```
29 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jregistry/jregistry.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JREGISTRY
4 | 1.0.0
5 | June 2018
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JREGISTRY_DESC
12 |
13 | language
14 | jregistry.php
15 | jregistry.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jsession/jsession.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JSESSION
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JSESSION_DESC
12 |
13 | language
14 | jsession.php
15 | jsession.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jposition/jposition.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JPOSITION
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JPOSITION_DESC
12 |
13 | language
14 | jposition.php
15 | jposition.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jprofiler/jprofiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_JPROFILER
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_JPROFILER_DESC
12 |
13 | language
14 | jprofiler.php
15 | jprofiler.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/unserialize/unserialize.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PLG_TWIG_UNSERIALIZE
4 | 1.0.0
5 | October 2017
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | PLG_TWIG_UNSERIALIZE_DESC
12 |
13 | language
14 | unserialize.php
15 | unserialize.xml
16 |
17 |
18 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/cache/language/en-GB/en-GB.plg_twig_cache.ini:
--------------------------------------------------------------------------------
1 | ; plg_twig_cache
2 | ; Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
3 | ; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE
4 | ; Note : All ini files need to be saved as UTF-8
5 |
6 | PLG_TWIG_CACHE="Twig - Cache"
7 | PLG_TWIG_CACHE_DESC="Enables cache for twig"
8 |
9 | PLG_TWIG_CACHE_PARAM_ENABLED="Enable"
10 | PLG_TWIG_CACHE_PARAM_ENABLED_DESC="Do you want to enable the cache system? Using global will enable it when Joomla! cache is enabled."
11 | PLG_TWIG_CACHE_PARAM_ENABLED_OPTION_GLOBAL="-- Use global --"
12 | PLG_TWIG_CACHE_PARAM_MODE="Cache status"
13 | PLG_TWIG_CACHE_PARAM_MODE_DESC="Here you can enable/disable Twig cache."
14 | PLG_TWIG_CACHE_PARAM_MODE_OPTION_ENABLED="Enabled"
15 | PLG_TWIG_CACHE_PARAM_MODE_OPTION_DISABLED="Disabled"
16 |
--------------------------------------------------------------------------------
/ci/phpunit.ci.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | ../tests
10 |
11 |
12 |
13 |
15 |
18 |
19 |
20 |
21 | ../extensions/libraries/twig/src
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/View/FormView.php:
--------------------------------------------------------------------------------
1 | getModel();
31 |
32 | return array_merge(
33 | parent::loadLayoutData(),
34 | [
35 | 'form' => $model->getForm(),
36 | 'model' => $model
37 | ]
38 | );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/View/ItemView.php:
--------------------------------------------------------------------------------
1 | getModel();
31 |
32 | return array_merge(
33 | parent::loadLayoutData(),
34 | [
35 | 'item' => $model->getItem(),
36 | 'model' => $model
37 | ]
38 | );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/debug/language/en-GB/en-GB.plg_twig_debug.sys.ini:
--------------------------------------------------------------------------------
1 | ; plg_twig_debug
2 | ; Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
3 | ; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE
4 | ; Note : All ini files need to be saved as UTF-8
5 |
6 | PLG_TWIG_DEBUG="Twig - Debug"
7 | PLG_TWIG_DEBUG_DESC="Enables debug mode and dump function in twig"
8 |
9 | PLG_TWIG_DEBUG_PARAM_MODE="Enable debug"
10 | PLG_TWIG_DEBUG_PARAM_MODE_DESC="Select the method to enable debug in twig: Automatically: use joomla debug status. Always: use debug even if joomla debug is disabled. Never: disable debug even if joomla debug is enabled."
11 | PLG_TWIG_DEBUG_PARAM_MODE_OPTION_AUTO="Automatically"
12 | PLG_TWIG_DEBUG_PARAM_MODE_OPTION_ALWAYS="Always"
13 | PLG_TWIG_DEBUG_PARAM_MODE_OPTION_NEVER="Never"
14 |
--------------------------------------------------------------------------------
/docs/functions/jregistry.md:
--------------------------------------------------------------------------------
1 | ## jregistry($data = null)
2 |
3 | This function returns an instance of `Joomla\Registry\Registry::getInstance()`. It allows to handle data coming from extension params or to create setting objects with defaults.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `mixed` **$data** JSON string | Array.
12 |
13 | ### Returns
14 |
15 | `Joomla\Registry\Registry` A registry instance.
16 |
17 | ### Examples
18 |
19 | ```twig
20 | {% raw %}
21 | {# Create a registry object from module parameters #}
22 | {% set params = jregistry(module.params) %}
23 |
24 | {% if params.get('format') === 'short' %}
25 |
Short format selected in module params
26 | {% endif %}
27 |
28 | {% endraw %}
29 | ```
30 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/twig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Twig - Library
4 | twig
5 | September 2018
6 | Roberto Segura
7 | roberto@phproberto.com
8 | www.phproberto.com
9 | Copyright (C) 2017-2018 Roberto Segura López. All rights reserved.
10 | GNU General Public License version 2 or later, see LICENSE.
11 | 1.5.0
12 | Twig library
13 |
14 | form
15 | language
16 | layouts
17 | src
18 | vendor
19 | library.php
20 |
21 |
22 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/View/HtmlView.php:
--------------------------------------------------------------------------------
1 | $this
36 | ];
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/docs/filters/unserialize.md:
--------------------------------------------------------------------------------
1 | ## unserialize
2 |
3 | Filter to unserialize a variable. Equivalent to PHP's [`unserialize($variable)`](http://php.net/manual/en/function.unserialize.php)
4 |
5 | 1. [Returns](#returns)
6 | 2. [Examples](#examples)
7 |
8 | ### Returns
9 |
10 | The converted value is returned, and can be a boolean, integer, float, string, array or object.
11 |
12 | In case the passed string is not unserializeable, FALSE is returned and E_NOTICE is issued.
13 |
14 | ### Examples
15 |
16 | ```twig
17 | {# If you have serialized a variable in session you can recover it and unserialize it in twig #}
18 | {% raw %}{% set cartItems = jsession.get('cartItems', []) %}{% endraw %}
19 | {% raw %}{% if cartItems is not iterable %}{% endraw %}
20 | {% raw %}{% set cartItems = cartItems|unserialize %}{% endraw %}
21 | {% raw %}{% endif %}{% endraw %}
22 | ```
--------------------------------------------------------------------------------
/docs/functions/jhtml.md:
--------------------------------------------------------------------------------
1 | ## jhtml($key, $...)
2 |
3 | This function is a proxy of `HTMLHelper::_($key)`. It allows to access HTML drawing classes inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$key** The name of helper method to load, (prefix).(class).function prefix and class are optional and can be used to load custom html helpers.
12 | * `mixed` **$...** Optional parameters for the helper method.
13 |
14 | ### Returns
15 |
16 | `mixed` Result of HTMLHelper::call($function, $args)
17 |
18 | ### Examples
19 |
20 | ```twig
21 | {% raw %}
22 | {# Render a form token. It will render something like:
23 | #}
24 | {{ jhtml('form.token') }}
25 | {% endraw %}
26 | ```
27 |
--------------------------------------------------------------------------------
/phpunit.dist.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | ./tests
10 |
11 |
12 |
13 |
15 |
17 |
20 |
21 |
22 |
23 | ./extensions/libraries/twig/src
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/docs/functions/jtext_sprintf.md:
--------------------------------------------------------------------------------
1 | ## jtext_sprintf($string, $...)
2 |
3 | This function is a proxy of `Joomla\CMS\Language\Text::sprintf()`. It allows to use translatable strings inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$string** The format string.
12 | * `mixed` **$...** Replacements for string parts.
13 |
14 | ### Returns
15 |
16 | `string` The translated strings or the key if 'script' is true in the array of options.
17 |
18 | ### Examples
19 |
20 | ```twig
21 | {% raw %}
22 | {# Display the translation of the JNEXT_TITLE language string (which would be something like "Next article: %s"). It will show something like:
23 | Next article: My article title
24 | #}
25 | {{ jtext_sprintf('JNEXT_TITLE', 'My article title') }}
26 | {% endraw %}
27 | ```
28 |
--------------------------------------------------------------------------------
/tests/tests/Plugin/Stubs/SamplePlugin.php:
--------------------------------------------------------------------------------
1 | autoloadLanguage = true;
28 |
29 | $config = array();
30 | $config['name'] = 'Sample';
31 | $config['type'] = 'System';
32 | $config['params'] = new Registry;
33 |
34 | $dispatcher = \JEventDispatcher::getInstance();
35 |
36 | // Call the parent constructor
37 | parent::__construct($dispatcher, $config);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/Unserialize.php:
--------------------------------------------------------------------------------
1 | addGlobal('japp', Factory::getApplication());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jdoc/jdoc.php:
--------------------------------------------------------------------------------
1 | addGlobal('jdoc', Factory::getDocument());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JUri.php:
--------------------------------------------------------------------------------
1 | addExtension(new JHtml);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jtext/jtext.php:
--------------------------------------------------------------------------------
1 | addExtension(new JText);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/docs/functions/juser.md:
--------------------------------------------------------------------------------
1 | ## juser($id = null)
2 |
3 | This function is a proxy of `Joomla\CMS\Factory::getUser()`. It allows to retrieve users to use them inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `integer` **$id** [optional] User to load. Default: use active user
12 |
13 | ### Returns
14 |
15 | `Joomla\CMS\User\User` The User object.
16 |
17 | ### Examples
18 |
19 | ```twig
20 | {% raw %}
21 | {# Retrieve active user not using any id. This is not usually required because you can already use `juser` global var #}
22 | {% set activeUser = juser() %}
23 |
24 | {# Retrieve the user with id: 668 #}
25 | {% set user = juser(668) %}
26 |
27 | {# Let's test if user was found #}
28 | {% if user.get('guest') %}
29 | User could not be loaded
30 | {% else %}
31 | User found with email: {{ user.email }}
32 | {% endif %}
33 | {% endraw %}
34 | ```
35 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JUser.php:
--------------------------------------------------------------------------------
1 | addExtension(new JArray);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JRoute.php:
--------------------------------------------------------------------------------
1 | addExtension(new JRoute);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jlayout/jlayout.php:
--------------------------------------------------------------------------------
1 | addExtension(new JLayout);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jposition/jposition.php:
--------------------------------------------------------------------------------
1 | addExtension(new JPosition);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JSession.php:
--------------------------------------------------------------------------------
1 | addExtension(new Unserialize);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jprofiler/jprofiler.php:
--------------------------------------------------------------------------------
1 | addExtension(new JProfiler);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jregistry/jregistry.php:
--------------------------------------------------------------------------------
1 | addExtension(new JRegistry);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JLanguage.php:
--------------------------------------------------------------------------------
1 | addExtension(new JModuleHelper);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JProfiler.php:
--------------------------------------------------------------------------------
1 | pluginPath)
38 | {
39 | $reflection = new \ReflectionClass($this);
40 |
41 | $this->pluginPath = dirname($reflection->getFileName());
42 | }
43 |
44 | return $this->pluginPath;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/library.php:
--------------------------------------------------------------------------------
1 | load('lib_twig', __DIR__);
37 |
38 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JText.php:
--------------------------------------------------------------------------------
1 | getModel();
31 |
32 | return array_merge(
33 | parent::loadLayoutData(),
34 | [
35 | 'items' => $model->getItems(),
36 | 'state' => $model->getState(),
37 | 'pagination' => $model->getPagination(),
38 | 'filterForm' => $model->getFilterForm(),
39 | 'activeFilters' => $model->getActiveFilters(),
40 | 'model' => $model
41 | ]
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/juri/juri.php:
--------------------------------------------------------------------------------
1 | addExtension(new JUri);
37 | $environment->addGlobal('juri', Uri::getInstance());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/docs/functions/jlayout_render.md:
--------------------------------------------------------------------------------
1 | ## jlayout_render($layoutFile, $displayData = null, $basePath = '', $options = null)
2 |
3 | Fast rendering of JLayout files inside a twig layouts. Proxy of `\Joomla\CMS\LayoutHelper::render()`.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$layoutFile** Dot separated path to the layout file, relative to base path.
12 | * `mixed` **$displayData** [optional] Array|Object which the data for the layout file. Default: `null`
13 | * `string` **$basePath** [optional] Base path to use when loading layout files.
14 | * `mixed` **$options** [optional] Custom options to load. Registry or array format
15 |
16 | ### Returns
17 |
18 | `string` HTML with layout output
19 |
20 | ### Examples
21 |
22 | ```twig
23 | {% raw %}
24 | {# Render the joomla.html.treeprefix layout with ['level' => 10] as data #}
25 | {{ jlayout_render('joomla.html.treeprefix', {'level' : 10}) }}
26 | {% endraw %}
27 | ```
28 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Extension/JHtml.php:
--------------------------------------------------------------------------------
1 | ['html']
34 | ];
35 |
36 | return [
37 | new TwigFunction('jhtml', [HTMLHelper::class, '_'], $options)
38 | ];
39 | }
40 |
41 | /**
42 | * Get the name of this extension.
43 | *
44 | * @return string
45 | */
46 | public function getName() : string
47 | {
48 | return 'jhtml';
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Traits/HasLayoutData.php:
--------------------------------------------------------------------------------
1 | layoutData[__CLASS__]))
36 | {
37 | $this->layoutData[__CLASS__] = $this->loadLayoutData();
38 | }
39 |
40 | return $this->layoutData[__CLASS__];
41 | }
42 |
43 | /**
44 | * Load layout data.
45 | *
46 | * @return array
47 | */
48 | abstract protected function loadLayoutData();
49 | }
50 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/juser/juser.php:
--------------------------------------------------------------------------------
1 | addExtension(new JUser);
37 | $environment->addGlobal('juser', Factory::getUser());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/tests/Loader/TemplateLoaderTest.php:
--------------------------------------------------------------------------------
1 | getMethod('getTemplatePaths');
32 | $method->setAccessible(true);
33 |
34 | $expected = [
35 | JPATH_BASE . '/templates/' . \JFactory::getApplication()->getTemplate() . '/html'
36 | ];
37 |
38 | $this->assertSame($expected, $method->invoke($loader));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/docs/functions/jlayout_debug.md:
--------------------------------------------------------------------------------
1 | ## jlayout_debug($layoutFile, $displayData = null, $basePath = '', $options = null)
2 |
3 | Fast debug of JLayout files rendering inside a twig layouts. Proxy of `\Joomla\CMS\LayoutHelper::debug()`.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$layoutFile** Dot separated path to the layout file, relative to base path.
12 | * `mixed` **$displayData** [optional] Array|Object which the data for the layout file. Default: `null`
13 | * `string` **$basePath** [optional] Base path to use when loading layout files.
14 | * `mixed` **$options** [optional] Custom options to load. Registry or array format
15 |
16 | ### Returns
17 |
18 | `string` HTML with layout output + debug info
19 |
20 | ### Examples
21 |
22 | ```twig
23 | {% raw %}
24 | {# Debug the joomla.html.treeprefix layout with ['level' => 10] as data #}
25 | {{ jlayout_debug('joomla.html.treeprefix', {'level' : 10}) }}
26 | {% endraw %}
27 | ```
28 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jlang/jlang.php:
--------------------------------------------------------------------------------
1 | addExtension(new JLanguage);
37 | $environment->addGlobal('jlang', Factory::getLanguage());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/extensions/libraries/twig/src/Loader/TemplateLoader.php:
--------------------------------------------------------------------------------
1 | getTemplate() . '/html';
40 |
41 | if (is_dir($tplOverrides))
42 | {
43 | $paths[] = $tplOverrides;
44 | }
45 |
46 | return $paths;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/docs/functions/jroute.md:
--------------------------------------------------------------------------------
1 | ## jroute($url, $xhtml = true, $ssl = null)
2 |
3 | This function is a proxy of `Joomla\CMS\Router\Route::_()`. It allows to build SEF urls inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$url** Absolute or Relative URI to Joomla resource.
12 | * `boolean` **$xhtml** Replace & by & for XML compliance.
13 | * `integer` **$ssl** Secure state for the resolved URI.
14 | * 0: (default) No change, use the protocol currently used in the request
15 | * 1: Make URI secure using global secure site URI.
16 | * 2: Make URI unsecure using the global unsecure site URI.
17 |
18 | ### Returns
19 |
20 | `string` The translated humanly readable URL.
21 |
22 | ### Examples
23 |
24 | ```twig
25 | {% raw %}
26 | {# Load a profiler and mark to points before and after doing something #}
27 | View category
28 | {% endraw %}
29 | ```
30 |
--------------------------------------------------------------------------------
/extensions/plugins/twig/jsession/jsession.php:
--------------------------------------------------------------------------------
1 | addExtension(new JSession);
37 | $environment->addGlobal('jsession', Factory::getSession());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/docs/functions/jtext.md:
--------------------------------------------------------------------------------
1 | ## jtext($string, $jsSafe = false, $interpretBackSlashes = true, $script = false)
2 |
3 | This function is a proxy of `Joomla\CMS\Language\Text::_()`. It allows to use translatable strings inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$string** The string to translate.
12 | * `mixed` **$jsSafe** Boolean: Make the result javascript safe.
13 | * `boolean` **$interpretBackSlashes** To interpret backslashes (\\=\, \n=carriage return, \t=tabulation).
14 | * `boolean` **$script** To indicate that the string will be push in the javascript language store:
15 |
16 | ### Returns
17 |
18 | `string` The translated string or the key if $script is true.
19 |
20 | ### Examples
21 |
22 | ```twig
23 | {% raw %}
24 | {# Display the translation of the JENABLED language string. It will display something like:
25 | "Something is enabled" #}
26 | Something is {{ jtext('JENABLED') }}
27 | {% endraw %}
28 | ```
29 |
--------------------------------------------------------------------------------
/docs/functions/juri.md:
--------------------------------------------------------------------------------
1 | ## juri($uri = 'SERVER')
2 |
3 | This function is a proxy of `Joomla\CMS\Uri\Uri::getInstance()`. It allows to deal with URLs as objects inside twig layouts.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$uri** [optional] The URI to parse. Default: active URL
12 |
13 | ### Returns
14 |
15 | `Joomla\CMS\Uri\Uri` The Uri object.
16 |
17 | ### Examples
18 |
19 | ```twig
20 | {% raw %}
21 | {# Load a URL into a uri object. Add Itemid=1976, remove view=category and finally ouput it as string #}
22 | {% set uri = juri('index.php?option=com_content&view=category') %}
23 |
24 | {# Add Itemid=1976 to the uri #}
25 | {% do uri.setVar('Itemid', 1976) %}
26 |
27 | {# Remove view=category from the uri #}
28 | {% do uri.delVar('view') %}
29 |
30 | {# Print final URL #}
31 |
Final URL is: {{ uri.toString() }}
32 |
33 | {# This will also print the url because Uri implements `__toString()` magic method #}
34 |
Final URL is: {{ uri }}
35 | {% endraw %}
36 | ```
37 |
--------------------------------------------------------------------------------
/docs/functions/jmodule_get_module.md:
--------------------------------------------------------------------------------
1 | ## jmodule_get_module($name, $title = null)
2 |
3 | Get a module published on the current page by its name or folder.
4 |
5 | 1. [Parameters](#parameters)
6 | 1. [Returns](#returns)
7 | 2. [Examples](#examples)
8 |
9 | ### Parameters
10 |
11 | * `string` **$name** Name of the module (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs')
12 | * `array` **$title** [optional] Title of the module.
13 |
14 | ### Returns
15 |
16 | `\stdClass|null` - The first module found that matches the name if found. Empty object if module not found and name starts with `mod_`. Null otherwise.
17 |
18 | ### Examples
19 |
20 | ```twig
21 | {% raw %}
22 | {# Retrieve a `mod_menu` module #}
23 | {% set module = jmodule_get_module('mod_menu') %}
24 |
25 | {# Retrieve a `mod_menu` module by its name (name is the module element removing the mod_ part). #}
26 | {% set module = jmodule_get_module('menu') %}
27 |
28 | {# Retrieve a `mod_menu` module with a specific title. #}
29 | {% set module = jmodule_get_module('mod_menu', 'Main Menu') %}
30 |
31 | {% endraw %}
32 | ```
33 |
--------------------------------------------------------------------------------
/tests/tests/Field/Stubs/SampleField.php:
--------------------------------------------------------------------------------
1 | __DIR__ . '/tmpl',
37 | 'Unexisting' => __DIR__ . '/unexisting'
38 | ];
39 | }
40 |
41 | /**
42 | * Load available option groups
43 | *
44 | * @return array
45 | */
46 | protected function loadGroups() : array
47 | {
48 | return $this->loadGroups ?: parent::loadGroups();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/docs/functions/jprofiler.md:
--------------------------------------------------------------------------------
1 | ## jprofiler($prefix = '')
2 |
3 | This function is a proxy of `Joomla\CMS\Profiler\Profiler::getInstance()`. It allows to use a profiler to debug performance inside twig layouts.
4 | 1. [Parameters](#parameters)
5 | 1. [Returns](#returns)
6 | 2. [Examples](#examples)
7 |
8 | ### Parameters
9 |
10 | * `string` **$prefix** Prefix used to distinguish profiler objects.
11 |
12 | ### Returns
13 |
14 | `Joomla\CMS\Profiler\Profiler` A profiler instance.
15 |
16 | ### Examples
17 |
18 | ```twig
19 | {% raw %}
20 | {# Load a custom profiler with twig prefix. Best of jprofiler is that you can share profilers from PHP & twig to fully trace performance issues. #}
21 | {% set profiler = jprofiler('twig') %}
22 |
23 | {# echo memory & time consumed before doing something. If you want to hide in production while debugging an issue this you can use display: hidden in the container #}
24 |
{{ profiler.mark('before loading something') }}
25 |
26 | {# Here what you want to debug #}
27 |
28 | {# echo memory & time consumed after something. #}
29 |