I would like to add a method to an Entity. This method returns X characters from the Entity's title, and i would like to print this title in my twig file. Is it possible ?
twig :
<ul class="nav nav-pills nav-stacked">
{% for blog in listBlogs %}
<li>
<a href="{{ path('l3_blog_view', {'id': blog.id}) }}">
{{ blog.getTruncatedTitle }}
</a>
</li>
{% endfor %}
entity :
class Blog
{
/**
* @var string
*
* @ORM\Column(name="content", type="text")
*/
private $content;
public function setTruncatedTitle($content)
{
$this->content = "Hey";
return $this;
}
/**
* Get content
*
* @return string
*/
public function getTruncatedTitle()
{
return $this->content;
}
}