kayue / KayueWordpressBundle

A Symfony 2 bundle for providing WordPress repositories and authenticating users (login).
101 stars 43 forks source link

Difficulty linking directly to post #33

Closed Arsenic181 closed 10 years ago

Arsenic181 commented 10 years ago

After digging around a bit, looking for a simple way to link directly to a blog post, I've found that the only way I was able to do this was with the following twig code as the value for the href attribute:

{{ wp_find_one_option_by_name('siteurl').value ~ '/' ~ post.slug }}

This seems a bit verbose for what I think should be a simple {{ post.friendlyUrl }} or some such.

Am I missing something?

kayue commented 10 years ago

@Arsenic181 When don't you use Symfony's routing to build the URL?

# app/config/routing.yml
blog_show:
    path:      /blog/{slug}
    defaults:  { _controller: AcmeBlogBundle:Blog:show }
<a href="{{ url('blog_show', {'slug': post.slug}) }}">
  Read this blog post.
</a>

See: http://symfony.com/doc/current/book/routing.html

Arsenic181 commented 10 years ago

Hi @kayue,

I was able to get this to work, thanks. I had just assumed that your bundle had incorporated an easier way to accomplish this task out of the box. I understand that the manner in which permalinks are set up can change the URLs a bit, but if you don't plan to incorporate a "linkToPost" function or something like that, I'm sure it would be of great help to others to mention this.

I am relatively new to Symfony though, so perhaps I just missed something that others might see straight away.

kayue commented 10 years ago

=D