original_string: public function render_from_template($templatename, $context) {
          static $templatecache = array();
          $mustache = $this->get_mustache();
  
          try {
              // Grab a copy of the existing helper to be restored later.
              $uniqidhelper = $mustache->getHelper('uniqid');
          } catch (Mustache_Exception_UnknownHelperException $e) {
              // Helper doesn't exist.
              $uniqidhelper = null;
          }
  
          // Provide 1 random value that will not change within a template
          // but will be different from template to template. This is useful for
          // e.g. aria attributes that only work with id attributes and must be
          // unique in a page.
          $mustache->addHelper('uniqid', new \core\output\mustache_uniqid_helper());
          if (isset($templatecache[$templatename])) {
              $template = $templatecache[$templatename];
          } else {
              try {
                  $template = $mustache->loadTemplate($templatename);
                  $templatecache[$templatename] = $template;
              } catch (Mustache_Exception_UnknownTemplateException $e) {
                  throw new moodle_exception('Unknown template: ' . $templatename);
              }
          }
  
          $renderedtemplate = trim($template->render($context));
  
          // If we had an existing uniqid helper then we need to restore it to allow
          // handle nested calls of render_from_template.
          if ($uniqidhelper) {
              $mustache->addHelper('uniqid', $uniqidhelper);
          }
  
          return $renderedtemplate;
      }
code: public function render_from_template($templatename, $context) {
          static $templatecache = array();
          $mustache = $this->get_mustache();
  
          try {
              // Grab a copy of the existing helper to be restored later.
              $uniqidhelper = $mustache->getHelper('uniqid');
          } catch (Mustache_Exception_UnknownHelperException $e) {
              // Helper doesn't exist.
              $uniqidhelper = null;
          }
  
          // Provide 1 random value that will not change within a template
          // but will be different from template to template. This is useful for
          // e.g. aria attributes that only work with id attributes and must be
          // unique in a page.
          $mustache->addHelper('uniqid', new \core\output\mustache_uniqid_helper());
          if (isset($templatecache[$templatename])) {
              $template = $templatecache[$templatename];
          } else {
              try {
                  $template = $mustache->loadTemplate($templatename);
                  $templatecache[$templatename] = $template;
              } catch (Mustache_Exception_UnknownTemplateException $e) {
                  throw new moodle_exception('Unknown template: ' . $templatename);
              }
          }
  
          $renderedtemplate = trim($template->render($context));
  
          // If we had an existing uniqid helper then we need to restore it to allow
          // handle nested calls of render_from_template.
          if ($uniqidhelper) {
              $mustache->addHelper('uniqid', $uniqidhelper);
          }
  
          return $renderedtemplate;
      }
code_tokens: public function render_from_template ( $ templatename , $ context ) { static $ templatecache = array ( ) ; $ mustache = $ this -> get_mustache ( ) ; try { // Grab a copy of the existing helper to be restored later. $ uniqidhelper = $ mustache -> getHelper ( 'uniqid' ) ; } catch ( Mustache_Exception_UnknownHelperException $ e ) { // Helper doesn't exist. $ uniqidhelper = null ; } // Provide 1 random value that will not change within a template // but will be different from template to template. This is useful for // e.g. aria attributes that only work with id attributes and must be // unique in a page. $ mustache -> addHelper ( 'uniqid' , new \ core \ output \ mustache_uniqid_helper ( ) ) ; if ( isset ( $ templatecache [ $ templatename ] ) ) { $ template = $ templatecache [ $ templatename ] ; } else { try { $ template = $ mustache -> loadTemplate ( $ templatename ) ; $ templatecache [ $ templatename ] = $ template ; } catch ( Mustache_Exception_UnknownTemplateException $ e ) { throw new moodle_exception ( 'Unknown template: ' . $ templatename ) ; } } $ renderedtemplate = trim ( $ template -> render ( $ context ) ) ; // If we had an existing uniqid helper then we need to restore it to allow // handle nested calls of render_from_template. if ( $ uniqidhelper ) { $ mustache -> addHelper ( 'uniqid' , $ uniqidhelper ) ; } return $ renderedtemplate ; }
docstring: Renders a template by name with the given context.
  
  The provided data needs to be array/stdClass made up of only simple types.
  Simple types are array,stdClass,bool,int,float,string
  
  @since 2.9
  @param array|stdClass $context Context containing data for the template.
  @return string|boolean
docstring_tokens: Renders a template by name with the given context .