stephpy/timeline-bundle

customize the templates

Closed this issue · 8 comments

Hello!
I want, customize some templates. For example I have photo.html.twig, and I want to show the image.

But actually I see in my template is:

<span class="directComplement">5114b5a1716e49.81836565.png</span>

How can I personalize the render of each template of verb?

Thanks ! ; )

Hi, it's explained here: renderer

If your verb is "own" and your config is:

# Define
render:
    path:     'AcmeBundle:Timeline'

Create the file AcmeBundle/Resouces/views/Timeline/own.html.twig

You could use themes too, if it's a photo model, you may want to render <img ....> all the time.

Yes @stephpy.

I read the documentation, but I have a template photo.html.twig and it show a div tag.

I want to show the img, i.e. <img src="use the info of directComplement"/> no <span class="directComplement">borja-5114b74163e933.35108703.png</span>

You understand me now?

Thanks for to reply

Ok, let use example with verb publish

Chuck Norris publish photo1.jpg

ChuckNorris => Subject
publish => verb
photo1.jpg => directComplement

Here we have to create a publish.html.twig and put it inside.

{{ timeline_component_render(timeline, 'subject') }}
just published picture:
{# timeline.getComponent('directComplement') is returning a Component OR NULL if not exists #}
{# timeline.getComponent('directComplement').data is returning an Object (if your picture is an object) or a string #}

So, something like that should works.
<img src="{{ timeline.getComponent('directComplement').data }}" />

If picture is an object, you can use themes:

config.yml

spy_timeline:
  render:
    resources:
        - 'YourBundle:Timeline:components.html.twig'

And on this file, define:

{# to overwride each components of \Acme\FooBundle\Entity\Picture #}
{% block _acme_foobundle_entity_picture_default_component %}
    <img src="{{ value }}" />
{% endblock _acme_foobundle_entity_picture_default_component %}

And on template:

{{ timeline_component_render(timeline, 'directComplement') }}

aha thank you very much @stephpy : )

I now understand.

Another question I have is: how I can check that the action shown is of the user logged in?

I mean, for example: Chuck wrote a state, now want to delete it, I need check when the user of action is the user that is connected to display the delete option.

I have explained?

If i understand, you could do:

{% is_granted('IS_AUTHENTICATED_REMEMBERED')  and timeline.getComponent('subject').id == app.user.id %}
......
{% endif %}

Is it ok for you ?

yes it works!

But I used:

{% if is_granted('IS_AUTHENTICATED_REMEMBERED') and timeline.getComponent('subject').identifier == app.user.id %}
.....
{% endif %}

Because id is the id of timeline, and identifier is the id of user.

thanks you very much

You're welcome, but you should do:

timeline.getComponent('subject').data.id

Because identifier could be an id serialized, use it only if data hydrator filter or orm listener is activated.