Php echo woo commerce in blade

sage9
blade
woocommerce

#1

Hi all,

First time writing a theme with sage 9 here.

For some reason
{{ WC()->cart->get_cart_subtotal() }}
Outputs the html wrapped in double quotes which results in the html being posted as text in the browser
“<span class=“woocommerce-Price-amount amount”><span class=“woocommerce-Price-currencySymbol”>&pound;</span>0.00</span>”

However, using regular php tags,
<?php echo WC()->cart->get_cart_subtotal(); ?>
the correct html is output and £0.00 is displayed in the browser.

Is this a blade bug? To be honest I’m not keen on blade, to start with. It seems a little like re-writing php to use a different syntax. I’m really not sure that I see the point and its not very well covered in the book on how to actually use it.


#2

Hey @ralphonz,

Blade automatically escapes the content returned by {{ $something }} for security purposes (common in templating systems).

If you want to output raw HTML from Blade, use {!! $something !!}.

See here: https://laravel.com/docs/5.7/blade#displaying-data

Also, if you’re using WooCommerce you may find this useful: https://github.com/roots/sage-woocommerce

And welcome to using Sage!


#3

Thats great, thanks @mmirus

So many changes from sage 8 which I only used a few times! I guess thats web development for you, you take a summer off and…