Explorar el Código

Add twig function to get template file inside template

This changes the way how template files are included or extended

Add twig filter to get template file inside template

This changes the way how template files are included or extended
Angel Fernando Quiroz Campos hace 7 años
padre
commit
da569547cd
Se han modificado 44 ficheros con 87 adiciones y 69 borrados
  1. 29 11
      main/inc/lib/template.lib.php
  2. 1 1
      main/inc/lib/userportal.lib.php
  3. 1 1
      main/template/default/admin/career_dashboard.tpl
  4. 1 1
      main/template/default/admin/gradebook_dependency.tpl
  5. 1 1
      main/template/default/admin/gradebook_list.tpl
  6. 1 1
      main/template/default/admin/resource_sequence.tpl
  7. 2 2
      main/template/default/auth/inscription.tpl
  8. 1 1
      main/template/default/auth/session_catalog.tpl
  9. 1 1
      main/template/default/career/diagram.tpl
  10. 1 1
      main/template/default/forum/list.tpl
  11. 2 2
      main/template/default/javascript/editor/ckeditor/elfinder.tpl
  12. 1 1
      main/template/default/layout/blank.tpl
  13. 1 1
      main/template/default/layout/head.tpl
  14. 1 1
      main/template/default/layout/hot_courses.tpl
  15. 2 2
      main/template/default/layout/layout_1_col.tpl
  16. 5 5
      main/template/default/layout/layout_2_col.tpl
  17. 1 1
      main/template/default/layout/layout_3_col.tpl
  18. 1 1
      main/template/default/layout/no_layout.tpl
  19. 4 4
      main/template/default/layout/page.tpl
  20. 3 3
      main/template/default/layout/page_header.tpl
  21. 2 2
      main/template/default/layout/show_footer.tpl
  22. 2 2
      main/template/default/layout/show_header.tpl
  23. 1 1
      main/template/default/learnpath/view.tpl
  24. 2 2
      main/template/default/mail/mail.tpl
  25. 1 1
      main/template/default/portfolio/list.html.twig
  26. 1 1
      main/template/default/session/resume_session.tpl
  27. 1 1
      main/template/default/skill/skill_wheel.js.tpl
  28. 1 1
      main/template/default/skill/skill_wheel.tpl
  29. 1 1
      main/template/default/skill/skill_wheel_student.tpl
  30. 1 1
      main/template/default/social/add_groups.tpl
  31. 1 1
      main/template/default/social/edit_profile.tpl
  32. 1 1
      main/template/default/social/friends.tpl
  33. 1 1
      main/template/default/social/group_view.tpl
  34. 1 1
      main/template/default/social/group_waiting_list.tpl
  35. 1 1
      main/template/default/social/groups.tpl
  36. 1 1
      main/template/default/social/groups_topics.tpl
  37. 1 1
      main/template/default/social/home.tpl
  38. 1 1
      main/template/default/social/inbox.tpl
  39. 1 1
      main/template/default/social/invitations.tpl
  40. 1 1
      main/template/default/social/myfiles.tpl
  41. 1 1
      main/template/default/social/profile.tpl
  42. 1 1
      main/template/default/social/search.tpl
  43. 1 1
      main/template/default/social/whoisonline.tpl
  44. 1 1
      main/template/default/work/view.tpl

+ 29 - 11
main/inc/lib/template.lib.php

@@ -171,6 +171,7 @@ class Template
                 'name' => 'format_date',
                 'callable' => 'Template::format_date',
             ],
+            ['name' => 'get_template', 'callable' => 'Template::findTemplateFilePath'],
         ];
 
         foreach ($filters as $filter) {
@@ -479,33 +480,50 @@ class Template
 
     /**
      * Returns the sub-folder and filename for the given tpl file.
-     * If template not found in overrides/ or custom template folder, the
-     * default template will be used.
+     *
+     * If template not found in overrides/ or custom template folder, the default template will be used.
      *
      * @param string $name
      *
      * @return string
      */
-    public function get_template($name)
+    public static function findTemplateFilePath($name)
     {
+        $sysCodePath = api_get_path(SYS_CODE_PATH);
+
         // Check if the tpl file is present in the main/template/overrides/ dir
         // Overrides is a special directory meant for temporary template
         // customization. It must be taken into account before anything else
-        $file = api_get_path(SYS_CODE_PATH).'template/overrides/'.$name;
-        if (is_readable($file)) {
-            return 'overrides/'.$name;
+        if (is_readable($sysCodePath."template/overrides/$name")) {
+            return "overrides/$name";
         }
+
+        $defaultFolder = api_get_configuration_value('default_template');
+
         // If a template folder has been manually defined, search for the right
         // file, and if not found, go for the same file in the default template
-        if ($this->templateFolder != 'default') {
+        if ($defaultFolder && $defaultFolder != 'default') {
             // Avoid missing template error, use the default file.
-            $file = api_get_path(SYS_CODE_PATH).'template/'.$this->templateFolder.'/'.$name;
-            if (!file_exists($file)) {
-                return 'default/'.$name;
+            if (file_exists($sysCodePath."template/$defaultFolder/$name")) {
+                return "$defaultFolder/$name";
             }
         }
 
-        return $this->templateFolder.'/'.$name;
+        return "default/$name";
+    }
+
+    /**
+     * Call non-static for Template::findTemplateFilePath
+     *
+     * @see Template::findTemplateFilePath()
+     *
+     * @param string $name
+     *
+     * @return string
+     */
+    public function get_template($name)
+    {
+        return self::findTemplateFilePath($name);
     }
 
     /**

+ 1 - 1
main/inc/lib/userportal.lib.php

@@ -1847,7 +1847,7 @@ class IndexManager
 
                             $this->tpl->assign('session_category', $categoryParams);
                             $sessions_with_category .= $this->tpl->fetch(
-                                "{$this->tpl->templateFolder}/user_portal/session_category.tpl"
+                                $this->tpl->get_template('user_portal/session_category.tpl')
                             );
                         }
                     }

+ 1 - 1
main/template/default/admin/career_dashboard.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     {{ form_filter }}

+ 1 - 1
main/template/default/admin/gradebook_dependency.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     <h3>

+ 1 - 1
main/template/default/admin/gradebook_list.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     {{ form }}

+ 1 - 1
main/template/default/admin/resource_sequence.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     <script>

+ 2 - 2
main/template/default/auth/inscription.tpl

@@ -1,7 +1,7 @@
 {%
     extends hide_header == true
-    ? template ~ "/layout/blank.tpl"
-    : template ~ "/layout/layout_1_col.tpl"
+    ? 'layout/blank.tpl'|get_template
+    : 'layout/layout_1_col.tpl'|get_template
 %}
 
 {% block content %}

+ 1 - 1
main/template/default/auth/session_catalog.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/page.tpl" %}
+{% extends 'layout/page.tpl'|get_template %}
 
 {% block body %}
     <script>

+ 1 - 1
main/template/default/career/diagram.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 

+ 1 - 1
main/template/default/forum/list.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 {% block content %}
 
 {{ introduction_section }}

+ 2 - 2
main/template/default/javascript/editor/ckeditor/elfinder.tpl

@@ -1,5 +1,5 @@
-{% extends template ~ "/layout/no_layout.tpl" %}
+{% extends 'layout/no_layout.tpl'|get_template %}
 
 {% block body %}
-    {% include template ~ '/javascript/editor/elfinder_standalone.tpl' %}
+    {% include 'javascript/editor/elfinder_standalone.tpl'|get_template %}
 {% endblock %}

+ 1 - 1
main/template/default/layout/blank.tpl

@@ -4,7 +4,7 @@
 <!--[if IE 8]>    <html lang="{{document_language}}" class="no-js lt-ie9"> <![endif]-->
 <!--[if gt IE 8]><!--><html lang="{{document_language}}" class="no-js"> <!--<![endif]-->
 <head>
-{% include template ~ "/layout/head.tpl" %}
+{% include 'layout/head.tpl'|get_template %}
 </head>
 <body dir="{{text_direction}}" class="{{section_name}}">
     <div class="page-blank">

+ 1 - 1
main/template/default/layout/head.tpl

@@ -54,7 +54,7 @@ $(function() {
 
 </script>
 
-{% include template ~ '/layout/header.js.tpl' %}
+{% include 'layout/header.js.tpl'|get_template %}
 
 {{ css_custom_file_to_string }}
 {{ css_style_print }}

+ 1 - 1
main/template/default/layout/hot_courses.tpl

@@ -35,7 +35,7 @@ $(document).ready( function() {
     </div>
     <div id="list-hot-courses" class="grid-courses">
         <div class="row">
-            {% include template ~ '/layout/hot_course_item.tpl' %}
+            {% include 'layout/hot_course_item.tpl'|get_template %}
         </div>
     </div>
 </section>

+ 2 - 2
main/template/default/layout/layout_1_col.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/page.tpl" %}
+{% extends 'layout/page.tpl'|get_template %}
 
 {% block body %}
     {% if plugin_main_top %}
@@ -18,7 +18,7 @@
 
     <div class="row">
         <div class="col-xs-12 col-md-12">
-            {% include template ~ "/layout/page_body.tpl" %}
+            {% include 'layout/page_body.tpl'|get_template %}
             {% block content %}
                 {% if content is not null %}
                     <section id="main_content">

+ 5 - 5
main/template/default/layout/layout_2_col.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/page.tpl" %}
+{% extends 'layout/page.tpl'|get_template %}
 
 {% block body %}
     {% if plugin_main_top %}
@@ -26,7 +26,7 @@
                 {% endif %}
 
                 {% block page_body %}
-                    {% include template ~ "/layout/page_body.tpl" %}
+                    {% include 'layout/page_body.tpl'|get_template %}
                 {% endblock %}
 
                 {% if welcome_to_course_block %}
@@ -55,9 +55,9 @@
                     </article>
                 {% endif %}
 
-                {% include template ~ "/layout/hot_courses.tpl" %}
+                {% include 'layout/hot_courses.tpl'|get_template %}
 
-                {% include template ~ "/session/sessions_current.tpl" %}
+                {% include 'session/sessions_current.tpl'|get_template %}
 
                 {% if plugin_content_bottom %}
                     <div id="plugin_content_bottom">
@@ -74,7 +74,7 @@
                     </div>
                 {% endif %}
 
-                {% include template ~ "/layout/login_form.tpl" %}
+                {% include 'layout/login_form.tpl'|get_template %}
 
                 {% if _u.logged  == 1 %}
                     {{ user_image_block }}

+ 1 - 1
main/template/default/layout/layout_3_col.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/page.tpl" %}
+{% extends 'layout/page.tpl'|get_template %}
 {% block body %}
 <div id="maincontent" class="maincontent">
     {{ plugin_courses_block }}

+ 1 - 1
main/template/default/layout/no_layout.tpl

@@ -4,7 +4,7 @@
 <!--[if IE 8]>    <html lang="{{document_language}}" class="no-js lt-ie9"> <![endif]-->
 <!--[if gt IE 8]><!--><html lang="{{document_language}}" class="no-js"> <!--<![endif]-->
 <head>
-{% include template ~ "/layout/head.tpl" %}
+{% include 'layout/head.tpl'|get_template %}
 </head>
 <body dir="{{text_direction}}" class="{{section_name}}">
 <section id="content-scorm">

+ 4 - 4
main/template/default/layout/page.tpl

@@ -6,7 +6,7 @@
 <html lang="{{ document_language }}" class="no-js"> <!--<![endif]-->
 <head>
 {% block head %}
-{% include template ~ "/layout/head.tpl" %}
+{% include 'layout/head.tpl'|get_template %}
 {% endblock %}
 </head>
 <body dir="{{ text_direction }}" class="{{ section_name }} {{ login_class }}">
@@ -34,7 +34,7 @@
     {% endif %}
 
     {% if show_header == true %}
-    {% include template ~ "/layout/page_header.tpl" %}
+    {% include 'layout/page_header.tpl'|get_template %}
     {% endif %}
     {% if show_course_shortcut is not null %}
         <div class="nav-tools">
@@ -56,10 +56,10 @@
 	</section>
 
     {% if show_footer == true %}
-	    {% include template ~ "/layout/page_footer.tpl" %}
+	    {% include 'layout/page_footer.tpl'|get_template %}
     {% endif %}
 
-    {% include template ~ '/layout/footer.js.tpl' %}
+    {% include 'layout/footer.js.tpl'|get_template %}
     </div>
   </body>
 </html>

+ 3 - 3
main/template/default/layout/page_header.tpl

@@ -3,7 +3,7 @@
     {{ bug_notification }}
 </div>
 {% block topbar %}
-    {% include template ~ "/layout/topbar.tpl" %}
+    {% include 'layout/topbar.tpl'|get_template %}
 {% endblock %}
 <div class="extra-header">{{ header_extra_content }}</div>
 <header id="header-section" class="header-movil">
@@ -53,6 +53,6 @@
     </div>
 </header>
 {% block menu %}
-    {% include template ~ "/layout/menu.tpl" %}
+    {% include 'layout/menu.tpl'|get_template %}
 {% endblock %}
-{% include template ~ "/layout/course_navigation.tpl" %}
+{% include 'layout/course_navigation.tpl'|get_template %}

+ 2 - 2
main/template/default/layout/show_footer.tpl

@@ -1,9 +1,9 @@
     {% if show_footer == true %}
             </div>
         </section>
-        {% include template ~ "/layout/page_footer.tpl" %}
+        {% include 'layout/page_footer.tpl'|get_template %}
     {% endif %}
     </div>
-    {% include template ~ '/layout/footer.js.tpl' %}
+    {% include 'layout/footer.js.tpl'|get_template %}
 </body>
 </html>

+ 2 - 2
main/template/default/layout/show_header.tpl

@@ -9,7 +9,7 @@
 <html lang="{{ document_language }}" class="no-js"> <!--<![endif]-->
 <head>
     {% block head %}
-        {% include template ~ "/layout/head.tpl" %}
+        {% include 'layout/head.tpl'|get_template %}
     {% endblock %}
 </head>
 <body dir="{{ text_direction }}" class="{{ section_name }} {{ login_class }}">
@@ -36,7 +36,7 @@
                 </form>
             </div>
         {% endif %}
-        {% include template ~ "/layout/page_header.tpl" %}
+        {% include 'layout/page_header.tpl'|get_template %}
         {% if show_course_shortcut is not null %}
             <div class="nav-tools">
                 {{ show_course_shortcut }}

+ 1 - 1
main/template/default/learnpath/view.tpl

@@ -66,7 +66,7 @@
             </div>
         {# TOC layout #}
         <div id="toc_id" class="scorm-body" name="toc_name">
-                {% include template ~ '/learnpath/scorm_list.tpl' %}
+                {% include 'learnpath/scorm_list.tpl'|get_template %}
             </div>
         {# end TOC layout #}
         </div>

+ 2 - 2
main/template/default/mail/mail.tpl

@@ -23,7 +23,7 @@
                 <table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;">
                     <tr>
                         <td>
-                            {% include template ~ '/mail/header.tpl' %}
+                            {% include 'mail/header.tpl'|get_template %}
                         </td>
                     </tr>
                     <tr>
@@ -35,7 +35,7 @@
                     </tr>
                     <tr>
                         <td>
-                            {% include template ~ '/mail/footer.tpl' %}
+                            {% include 'mail/footer.tpl'|get_template %}
                         </td>
                     </tr>
                 </table>

+ 1 - 1
main/template/default/portfolio/list.html.twig

@@ -4,7 +4,7 @@
 {% set delete_img = 'delete.png'|img(22, 'Delete'|get_lang) %}
 {% set baseurl = _p.web_self ~ '?' ~ (_p.web_cid_query ? _p.web_cid_query ~ '&' : '') %}
 
-{% import template ~ '/portfolio/items.html.twig' as items %}
+{% import 'portfolio/items.html.twig'|get_template as items %}
 
 {% if not allow_edit %}
     <h3>{{ user.completeName }} <small>{{ user.username }}</small></h3>

+ 1 - 1
main/template/default/session/resume_session.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 

+ 1 - 1
main/template/default/skill/skill_wheel.js.tpl

@@ -1,5 +1,5 @@
 {# topbar #}
-{% include template ~ "/layout/topbar.tpl" %}
+{% include 'layout/topbar.tpl'|get_template %}
 <script>
 
 var SkillWheel = {

+ 1 - 1
main/template/default/skill/skill_wheel.tpl

@@ -1,4 +1,4 @@
-{% include template ~ '/skill/skill_wheel.js.tpl' %}
+{% include 'skill/skill_wheel.js.tpl'|get_template %}
 <script>
     /* Skill search input in the left menu */
     function check_skills_sidebar() {

+ 1 - 1
main/template/default/skill/skill_wheel_student.tpl

@@ -1,4 +1,4 @@
-{% include template ~ '/skill/skill_wheel.js.tpl' %}
+{% include 'skill/skill_wheel.js.tpl'|get_template %}
 <script>
     /* Skill search input in the left menu */
     function check_skills_sidebar() {

+ 1 - 1
main/template/default/social/add_groups.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/edit_profile.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/friends.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/group_view.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row" xmlns="http://www.w3.org/1999/html">

+ 1 - 1
main/template/default/social/group_waiting_list.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/groups.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/groups_topics.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     <div class="row">

+ 1 - 1
main/template/default/social/home.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     <div class="row">

+ 1 - 1
main/template/default/social/inbox.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/invitations.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/myfiles.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/profile.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/search.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
 <div class="row">

+ 1 - 1
main/template/default/social/whoisonline.tpl

@@ -1,4 +1,4 @@
-{% extends template ~ "/layout/layout_1_col.tpl" %}
+{% extends 'layout/layout_1_col.tpl'|get_template %}
 
 {% block content %}
     <div class="row">

+ 1 - 1
main/template/default/work/view.tpl

@@ -24,4 +24,4 @@
 </p>
 {% endif %}
 
-{% include template ~ '/work/comments.tpl' %}
+{% include 'work/comments.tpl'|get_template %}