user1555112
user1555112

Reputation: 1977

Cakephp 2.5. : how to use html tags and autoLinkUrls in this case

I have a text part like this:

<p><?php echo __('<strong>some strong text</strong> some other text  THIS IS AN URL more other text <strong>more strong text</strong> and finally end of text'); ?></p>

I wonder what would be the best way to:

When setting the URL I would also like to use the Cake Style of $this->Html->Link() but I don't know how I can do this in this example above?

Upvotes: 1

Views: 78

Answers (2)

Compiler
Compiler

Reputation: 115

Here is how to do it.

<p>
    <?php 
         $string = '<strong>some strong text</strong> some other text ';
         $string .= 'https://www.example.com';
         $string .= ' more other text <strong>more strong text</strong> and finally <b>end of text</b>';
         echo $this->Html->link(__($string),'http://www2.test.com',['escape'=>false]); 
     ?>
</p>

Upvotes: 0

floriank
floriank

Reputation: 25698

Read the manual.

Using Variables in Translation Messages Translation functions allow you to interpolate variables into the messages using special markers defined in the message itself or in the translated string:

echo __("Hello, my name is {0}, I'm {1} years old", ['Sara', 12]);

Just generate your link $link = $this->Html->link(__('foo'), [/*...*/]); and pass $link to the __() functions 2nd arg as shown in the example above.

Read the whole section about the translations functions, there are a few more good to know things like plural / singular and number handling.

Upvotes: 3

Related Questions