PHP code example of vierwd / typo3-smarty

1. Go to this page and download the library: Download vierwd/typo3-smarty 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/ */

    

vierwd / typo3-smarty example snippets


// Classes/Controller/BlogController.php
namespace Example\ExampleBlog\Controller;

class BlogController extends \Vierwd\VierwdSmarty\Controller\ActionController {
	/**
	 * @var \Example\ExampleBlog\Domain\Repository\PostRepository
	 * @TYPO3\CMS\Extbase\Annotation\Inject
	 */
	protected $postRepository;

	public function listAction() {
		$posts = $this->postRepository->findAll();
		$this->view->assign('posts', $posts);
	}
}
Smarty
{* Resources/Private/Templates/Blog/List.tpl *}

{foreach $posts as $post}
	<div class="post">
		<h1>{$post->getTitle()}</h1>

		{$post->getContent()|escape|nl2p nofilter}
	</div>
{/foreach}
smarty
{capture assign=text}
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
{/capture}

{typoscript header='TypoScript Example' bodytext=$text CType=text}
lib.parseFunc_RTE >
10 < tt_content
{/typoscript}
html
<div class="csc-default">
<header class="csc-header"><h1>TypoScript Example</h1></header>
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
</div>
smarty
{capture assign=text}
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
{/capture}

{$data=[
	CType => text,
	header => 'TypoScript Example',
	header_layout => 1,
	bodytext => $text
]}

{typoscript data=$data header_layout=2}
lib.parseFunc_RTE >
10 < tt_content
{/typoscript}
html
<div class="csc-default">
<header class="csc-header"><h2>TypoScript Example</h2></header>
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
</div>
smarty
<nav class="main-navigation">
	<ul>
	{foreach $menu as $item}
		{$hasSubmenu = $menuObject->isSubMenu($item.uid)}
		{$isActive = $menuObject->isActive($item.uid)}
		<li class="{if $isActive}active{/if}">
			<a href="{$item.uid|typolink}">
				{$item.nav_title|default:$item.title}
			</a>
			{$menuObject->submenu($item.uid) nofilter}
		</li>
	{/foreach}
	</ul>
</nav>