Welcome Guest, Not a member yet? Register   Sign In
Parse custom html tags?
#1

[eluser]mscahill[/eluser]
I took a look at CI's template parser, but this isn't going to fit my need on this project. I need to parse my custom tags before they ever get to the view. Here's an example of what I'm looking to do:

A custom tag like this would load a resultset into an array:
Code:
<query variable='users'>SELECT * FROM users</query>

Then a result (the username for user with ID of 12) could be accessed like so:
Code:
<var:users row='12' col='user_name' />
output:
Code:
Bobby

I would also need a tag like this to forward to my drilldown controller:
Code:
<drilldown name='user' value='Bobby'>Bobby</drilldown>
output:
Code:
<a href='http://example.com/drilldown/user/Bobby'>Bobby</a>

Any ideas? I've looked at regex, PHP DOM, etc. but don't know how I would accomplish something like this.
#2

[eluser]xwero[/eluser]
Is this something you want to do because everything can be done? Not even asp.net tags put sql statements in its tags.

Check out this or this to get your tags out of the file. To add the processed content you are on your own. a tag like drilldown you can regex with the result of the classes but the query and var:users is a two step process.

Another option is to put metadata in a placeholder tag and get is via ajax but if you have a lot of custom tags the loading of a page will be endless even if you display as soon as the metadata is processed.
#3

[eluser]mscahill[/eluser]
I'm building a reporting application. I'm looking for a way to create a sort of "report language" (XML?) so that it's not necessary to execute PHP tags in a template. The report "files" are actually saved in the database. Right now I have this sort of thing:

Code:
&lt;?php $query = $this->db->query("SELECT * FROM users");
$users = $query->result_array(); ?&gt;

<table>
&lt;?php foreach ($users AS $user) {
echo "<tr><td>" . $user['ID'] . "</td><td><a href='" . site_url("drilldown/user") . "/" . $user["name"] . "'>" . $user['name'] . "</a></td></tr>";
} ?&gt;
</table>
#4

[eluser]mscahill[/eluser]
I've had luck so far with this: http://www.phpbuilder.com/columns/scheff...hp3?page=1
His technique allows me to define actions for custom HTML tags. For example, I was able to turn this:
Code:
<drilldown query='SELECT * FROM users'>This is a list of users:</drilldown>

into this:
Code:
<p>This is a list of users</p>
<table>
<tr><td>1</td><td>Bobby</td></tr>
<tr><td>2</td><td>Fred</td></tr>
</table>

Now I just need to figure out how to load SQL assets into arrays, and query them from a different custom tag. Easier said than done...
#5

[eluser]mscahill[/eluser]
By the way, where do I offer resources to the CI community? I could provide the model for parsing XML that I modified from the code above. It might come in handy to someone else.
#6

[eluser]Michael;[/eluser]
Greets mscahill,

The best way to offer something back to the community is to place it in the wiki ... Though I would suggest you create a thread in the Ignited Code forum as well as it will make it easier for someone who is searching the forums to locate your contribution.

Michael;




Theme © iAndrew 2016 - Forum software by © MyBB