Code Monkey home page Code Monkey logo

Comments (4)

buchanae avatar buchanae commented on June 23, 2024

apologies if I'm just misunderstanding what the url extension should do.

possibly you could drop this in favor of the helper extension, which allows url.site (I think?)

from kohana-twig.

aron avatar aron commented on June 23, 2024

Route::get() works just fine for me. How are you using the tag?

 {% url {route_name}, {parameters} %}

For example to load the edit action on the posts controller you would use the following:

{% url "default", ["controller":"posts", "action":"edit", "id":"my-post"] %}

Hope that helps?

Cheers,

Aron

from kohana-twig.

buchanae avatar buchanae commented on June 23, 2024

I see, thanks.

Should that tag be called "route" then? Since it relates directly to the Route helper, that makes more sense to me anyway.

I was using this tag, trying to link to a static asset e.g.

{% url '/img/foo.png' %}

or, in general, I find it easier, simpler, clearer to just use URL format (especially if the template coders are not backend devs, and shouldn't need to know controller, action, etc)

e.g.
{% url 'posts/edit/1' %}

from kohana-twig.

aron avatar aron commented on June 23, 2024

Ideally you should be able to rename the tags by simply creating your own Twig_URL_TokenParser and redefining the getTag() method to return 'route'. However unfortunately the Twig module doesn't conform to the Kohana design principals with it's tag implementation.

For your static assets you could either create a tag module for the URL class or a simpler solutions would be to define a "base_url" variable in your controller set to URL::base(TRUE, TRUE) and use this in your views.

 <img src="{{ base_url }}/img/foo.png" />

I'd argue that you should always use the controllers and actions in your views even if it does make them appear more complex as it decouples the site URLs from the templates. This means that in the future should you decide to modify your applications routes, for example adding a prefix or swapping the parameters around, all your templates will still generate correct links and not require any modification.

Cheers,

Aron

from kohana-twig.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.