parsing in view layer

edited August 2014 in Modules
How can we allow the layer also able to parse syntax like {site_url()}? currently only editable page created at the backend able to parse this kind of syntax, but manually created view files are unable to.

Comments

  • edited 2:43PM
    There is a function called parse_template_syntax found under the MY_string_helper that can be used:
    http://docs.getfuelcms.com/helpers/my_string_helper

    Additionally, with a static view, you can pass it the variable of "parse_view" equal to TRUE in which case it will run the template parser on the view file.
  • edited 2:43PM
    how to make them work on parsing variables in layout?

    function index(){
    if(!isset($_SESSION)) session_start();

    if(isset($_SESSION['LoggedIn'])){
    header('Location: profile');
    exit;
    }
    $vars['parse_view']=TRUE;
    $vars['layout']='general';

    $this->fuel->pages->render('signup', $vars);
    }


    my signup template is using a layout, all the {} variables in the layout is not parsed.
  • edited 2:43PM
    So are the {...} in a particular layout view file (e.g. views/_layouts/main.php). Or are the {...} in the values entered in the CMS layout fields?
  • edited 2:43PM
    {...} in a particular layout view file (e.g. views/_layouts/main.php)
  • edited 2:43PM
    How are you embedding the variables? Are you including the $:
    {$page_title}
    Also, you can just use PHP syntax:
    <?=$page_title?>
  • edited 2:43PM
    Used $this->asset->js()
  • edited August 2014
    then in the view file ( not the layout file), i used fuel_set_var('js','a,b,c'); on layout file i used <?php
    echo $this->asset->js($js);
    ?>

    beside these,
    are also not parsed.

    The flow is there is a signup.php controller and a signup.php view which use a main.php layout file. all above codes lied in main.php
  • edited 2:43PM
    So you are saying that you are using a view of "views/signup.php" that has fuel_set_var('js','a,b,c'); set at the top of it. You then have in your views/_layouts/main.php layout file:
    echo $this->asset->js($js); // (As an FYI, you can use the "js($js)" function instead of $this->asset->js($js).)
    Then in your controller you call:
    $this->fuel->pages->render('signup', $vars);
    And the js method isn't outputting the script tags for a, b and c. Is that correct?
  • edited 2:43PM
    Yes, boss, u got it
  • edited 2:43PM
    In the code above, you specified the $vars['layout'] = 'general' and not 'main'. Is that still the case?

    I just ran a test doing the same thing (but using the layout of 'main') and it worked OK. Is there a "signup" page also created in the CMS, or is it just a static view file?
  • edited 2:43PM
    General and main are examples given, in actual code they are same. Signup is a static view file not created at backend
  • edited 2:43PM
    Hmmm... I'm not sure. I'm not able to replicate that problem. You should be able to call fuel_set_var from within your view file and it will affect variables in the layout file like "js". Maybe perhaps try it with just a simple view called "test.php" that doesn't use a controller but has the fuel_set_var('js','a,b,c'); in it.
  • edited 2:43PM
    solved by echo out the result
Sign In or Register to comment.