Get support for ericlbarnes/simpletags
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
ericlbarnes/simpletags
Simpletags
Version 1.2
- Author: Dan Horrigan
DESCRIPTION
Simpletags is exactly what it sounds like...a simple way to use tags in your PHP application. This allows you to have tags that look like this:
{something:other}
{date format="m/d/Y"}
{blog:entries count="5"}
Stuff here
{/blog:entries}
INSTALLATION
- Just include the Simpletags.php file into your app
CodeIgniter
- Put Simpletags.php into your application/libraries folder
- Load it like normal: @$this->load->library('simpletags');@ (or autoload it).
USAGE
You can send a config array to the constructor with the following options (these are the defaults):
array(
'l_delim' => '{',
'r_delim' => '{',
'trigger' => '',
);
You can also set the delimiters and triggers via the following functions:
$simpletags = new Simpletags();
$simpletags->set_delimitiers('{', '}');
$simpletags->set_trigger('foo:');
To parse a string of text you simply call the parse() function. The parse function accepts 3 parameters:
- $content - The content to parse
- [optional] $data - a keyed array of data to replace tag vars with (more below)
- [optional] $callback - A callback that will be called for each tag.
Normal Return
If no callback is specified then the function will return an array. Consider this is the content you sent:
Hello there.
{rest:get url="http://example.com/api" type="json"}
Stuff here
{/rest:get}
Bye.
Parse would return this:
Array
(
[content] => Hello there.
marker_0k0dj3j4nJHDj22j
Bye.
[tags] => Array
(
[0] => Array
(
[full_tag] => {rest:get url="http://example.com/api" type="json"}
Stuff here
{/rest:get}
[attributes] => Array
(
[url] => http://example.com/api
[type] => json
)
[segments] => Array
(
[0] => rest
[1] => get
)
[content] =>
Stuff here
[marker] => marker_0k0dj3j4nJHDj22j
)
)
)
Using the Data Array
The data array is a keyed array who's contents will replace tags with the same name. Example:
{foo:bar}
Would be replaced with "Hello World" when the following data array is sent to the parse function:
$data['foo']['bar'] = "Hello World"
You can use tag pairs to loop through data as well:
Tag:
{books}
{title} by {author}<br />
{/books}
Data
$data = array(
'books' => array(
array(
'title' => 'PHP for Dummies',
'author' => 'John Doe'
),
array(
'title' => 'CodeIgniter for Dummies',
'author' => 'Jane Doe'
)
)
);
Resulting Output
PHP for Dummies by John Doe
CodeIgniter for Dummies by Jane Doe
Callbacks
The callback must be in a form that is_callable() accepts (typically array(object, method)). The callbac function should take 1 parameter (an array).
The callback will be sent the tag information in the form of an array. Consider the following
{rest:get url="http://example.com/api" type="json"}
Stuff here
{/rest:get}
Would send the callback function the following array:
Array
(
[full_tag] => {rest:get url="http://example.com/api" type="json"}
Stuff here
{/rest:get}
[attributes] => Array
(
[url] => http://example.com/api
[type] => json
)
[segments] => Array
(
[0] => rest
[1] => get
)
[content] =>
Stuff here
[marker] => marker_0k0dj3j4nJHDj22j
)
CodeIgniter Usage
You use it the same as above, except you would use the following:
$this->load->library('simpletags');
$content = $this->simpletags->parse($content, $data, array($this, 'parser_callback'));
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2