Welcome Guest, Not a member yet? Register   Sign In
Improved Template Parser
#1

[eluser]pedro_fp_simoes[/eluser]
Hi,
I have modified the original CI Template parser to suit my needs, the changes are:
1. Fixed error when the parser get's an stdClass;
2. Added the possibility to have the same iteration in 2 different places;
3. Added simple conditional branches;
4. Fixed compatibility with views, so you can use templates where was a view;

How to use:
The same way you use the original parser, but:
1. Must place the file Parser2.php in application/libraries;
2. Must load with the name parser2 instead of parser;
3. You can place the same iteration in 2 different places;
4. You can use simple conditionals,
{boolean_var}string{/boolean_var} or
{!boolean_var}string{/boolean_var}

The purpose was to maintain the same structure of the original and add some small but essencial features.

Code:
<html>
    <head>
       <title>{blog_title}</title>
    </head>
    <body>
      {show_heading}
      <h3>{blog_heading}</h3>
      {/show_heading}

      {blog_entries}
      <h5>{title}</h5>
      {has_excerpt}
      <p>{excerpt}</p>
      <a href="{site_url}/contents/{id}">Read more ...</a>
      {/has_excerpt}{!has_excerpt}
      <p>{body}</p>
      {/has_excerpt}
      
      {/blog_entries}
   &lt;/body&gt;
&lt;/html&gt;

for now I have a problem defining the else part with regex, the workaround is to use 2 separate if's, like this {/has_excerpt}{!has_excerpt}
#2

[eluser]pedro_fp_simoes[/eluser]
Minor correction inside iterations

Meanwhile do you have any feedback to give?
#3

[eluser]pedro_fp_simoes[/eluser]
What do you think about this ideas?

1. Using {if bool_var}{/bool_var} instead of {bool_var}{/bool_var}
2. {foreach array_var}{/array_var} instead of {array_var}{/array_var}
3. for the else part of the if, use of {else bool_var}
4. add an short if form like this {bool_var?} {:bool_var} {/bool_var}


Thanks in advance
#4

[eluser]pedro_fp_simoes[/eluser]
Hi guys,

I have now the complete list of modifications that I want do:
1. {if bool_var} {else bool_var} {/bool_var} -> test also with the empty function;
2. {foreach array_var} {/array_var} -> a) and iterates;
3. {partial view_name} -> loads in this area the output from another parsed view;
4. {module controller_name/action/vars} -> loads in this area the reply from another controller (needs HMVC);
5. {variable} -> same as before;
6. {using variable} -> a);
7. {lang text} -> replace with translated text (needs CI Language Class);

a) uses a object or associative array, creates a sub-environment, if value is a object then uses the get_object_vars function and also the empty function;

What do you think about that?
I will need some help with some advanced regex's
#5

[eluser]InsiteFX[/eluser]
You extend the library and then place it in application/core

Code:
class MY_Parser extends CI_Parser {

}

InsiteFX
#6

[eluser]pedro_fp_simoes[/eluser]
[quote author="InsiteFX" date="1299467864"]You extend the library and then place it in application/core

Code:
class MY_Parser extends CI_Parser {

}

InsiteFX[/quote]

Hi, you are right, but I will maintain separate classes instead of inherit from the original, because I will introduce a lot of modifications in the core of the Parser, but I will study the possibility to place the class in the application/libraries folder to maintain the CI system folder untouched.

Thanks, Pedro Simões
#7

[eluser]pedro_fp_simoes[/eluser]
Without any modifications, I tested it so you can place the file Parser2.php in application/libraries instead of system/application, in this way you maintain your system CI folder intact

Quote:1. Must place the file Parser2.php in application/libraries;

modified on 1st reply

Quote:I have now the complete list of modifications that I want do:
1. {if bool_var} {else bool_var} {/bool_var} -> test also with the empty function;
2. {foreach array_var} {/array_var} -> a) and iterates;
3. {partial view_name} -> loads in this area the output from another parsed view;
4. {module controller_name/action/vars} -> loads in this area the reply from another controller (needs HMVC);
5. {variable} -> same as before;
6. {using variable} -> a);
7. {lang text} -> replace with translated text (needs CI Language Class);

a) uses a object or associative array, creates a sub-environment, if value is a object then uses the get_object_vars function and also the empty function;

this new features are still to do, it will be implemented in the near future Wink

Thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB