Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorghismo
     
    Hello,

    In a view I've got the following localized string : _{Click on <a href="%1">this link</a>} and would like to paramterize the href (the %1 in this case should be replaced by the result of $url_helper->url_for(array('controller'=>'mycontroller', 'action'=>'myaction'));).

    How can I get this to work ?

    Thanks.
    • CommentAuthormerindol
     

    Hi.

    I know 2 methods :

    1. With a helper

    In the helper (either by creating the url in the template or in the helper

    function buildLink( $url = null ) { if( empty( $url ) ) $url = $this->_controller->url_for( array( 'controller'=>'mycontroller', 'action'=>'myaction' ) ); return( $this->_controller->t( 'Click on &lt;a href="%url">this link&lt;/a>', array( '%url' => $url ) ) ); }

    In the template

    &lt;%= buildLink ( url_for :action => 'mycontroller', :action => 'myaction' ) %>

    2. All in template

    &lt;% url = url_for :action => 'mycontroller', :action => 'myaction' %> _{Click on &lt;a href="%url">this link&lt;/a>} The traduction directive should automatically expend to this: &lt;?php echo $text_helper->translate( 'Click on &lt;a href="%url">this link&lt;/a>', array('%url => @$url)); ?> You can assign the $url variable in the controller if you don't like it in the template.

    P.S : I didn't test it, maybe it needs some adjustments. P.S.2 : Those < replacements suck :p

    •  
      CommentAuthorbermi
     

    Shorter using Sintags

    <%= t "Click on <a href='#{url_for :controller=>'mycontroller',:action=>'myaction'}'>this link</a>" %>
    
    • CommentAuthorghismo
     
    thank you bermi, I'll use your solution that works like a charm, thank you merindol as well for giving me this interesting pointer :)