1. Go to this page and download the library: Download rodnaph/morgan library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rodnaph / morgan example snippets
use Morgan\Template as T;
T::render(
'page.html',
array(
'.header h1' => T::content('Some Text')
)
);
# set the content of an element
T::content('Some new content')
# append content to an element
T::append('This please')
# prepend content to an element
T::prepend('Some string')
# use HTML as content for an element
T::htmlContent('<b>bold text</b>')
# set attributes of elements
T::setAttr('href', '/blog/post.html')
# remove attributes of elements
T::removeAttr('class')
# add classes to element
T::addClass('foo', 'bar', 'baz')
# remove classes from element
T::removeClass('foo', 'bar', 'baz')
# replace with some HTML
T::replaceWith('<b>Some HTML</b>')
# array of blog posts to show
$posts = array(
array(
'title' => 'First Post',
'summary' => 'Some short snippet',
'href' => '/blog/post-one.html'
),
array(
'title' => 'Another Post',
'summary' => 'And another short snippet',
'href' => '/blog/another-post.html'
)
);
# re-usable blog post summary snippet
$postSnippet = T::snippet(
'blog-posts.html',
'.post',
function($item) {
return array(
'h3 a' => T::all(
T::content($item['title']),
T::setAttr('href', $item['href'])
),
'p' => T::content($item['summary'])
);
}
);
# render the main template
T::render(
'blog-posts.html',
array(
'h1' => 'The Blog Posts Page',
'.posts' => T::map($postSnippet, $posts)
)
);
use Morgan\Template as T;
# create and echo the template
$t = new T('path/to/file.html');
echo $t->html(array(
'h1' => T::contect('Some title')
));
# snippet is exactly the same, but with a selector
$s = new T('path/to/file.html', '.some-selector');
echo $s->html(array(
'.description' => T::content('A Description')
));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.