• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot Access Global Variable in Loop

#1
Hello.

Im passed an array and some global variables array to view file.

Code:
$website_lang_array = array (
'LANG1' => 'Main',
'LANG2' => 'Blog',
'LANG3' => 'Templates',
'LANG4' => 'About',
'LANG5' => 'Contact',
'LANG6' => 'Login',
'LANG7' => 'Facebook Login',
'LANG8' => 'SignIn',
'LANG9' => 'Search...',
'LANG10' => 'Latest Contents',
'LANG11' => 'Show All',
'LANG12' => 'From BLOG',
'LANG13' => 'Visit Blog',
'LANG14' => '&copy 2016 All rights reserved',
'LANG15' => 'Category:',
);



if i use this variable a outside of lop such as

Code:
{LANG15}
{content}
   {content_id} - {content_title}
{/content}

this is working good. 


But when i try to access in loop such as



Code:
{content}
   {LANG15}
   {content_id} - {content_title}
{/content}

This is not working. i think its search {LANG15} in content array.

i must acces {LANG15} in loop. but how? Thanks inadvance.
Reply

#2
You are right: it's trying to load LANG15 from "content" array rather than main array. I don't think build-in Parser library has a solution for you. But you can use another parser library (I use Mustache myself https://github.com/bobthecow/mustache.php), but it will require additional work of setting it up.

P.S. I can send you link to my drop-in version of the library that requires no changes in your code to use it (e.g. $this->parser->parse).
Reply

#3
(02-09-2016, 03:22 PM)siburny Wrote: You are right: it's trying to load LANG15 from "content" array rather than main array. I don't think build-in Parser library has a solution for you. But you can use another parser library (I use Mustache myself https://github.com/bobthecow/mustache.php), but it will require additional work of setting it up.

P.S. I can send you link to my drop-in version of the library that requires no changes in your code to use it (e.g. $this->parser->parse).

thanks for reply. so, all other users using another parser libraries? this is weird. in a looop i can't access a variable :S this is enough for leave codeignitier.
Reply

#4
You can use variable in a loop. You have to put it inside a specific sub-array ("content" in your case). Most people tend to pass to view/parser variables that are needed for that particular template rather then throw everything at it and let template decide if it needs it.
Reply

#5
What I suggest you do is use language helper: lang - https://www.codeigniter.com/userguide3/h...elper.html

Then you just load a language file in CI and you don't need to pass anything to a view or parser in this case.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.