Using tags in Blade view #790
-
Hi all, I'm running into some trouble using tags in my blade views, specifically I'm using the tag like this: I tracked down the issue to this parse function in the Statamic codebase: // statamic/cms/src/Tags/Tags.php
/**
* Parse the tag pair contents.
*
* @param array $data Data to be parsed into template
* @return string
*/
public function parse($data = [])
{
if ($scope = $this->params->get('scope')) {
$data = Arr::addScope($data, $scope);
}
if (! $this->parser) {
return $data;
}
return Antlers::usingParser($this->parser, function ($antlers) use ($data) {
return $antlers
->parse($this->content, array_merge($this->context->all(), $data))
->withoutExtractions();
});
} It seems that I'm stuck using Blade for the time being so any help here is much appreciated. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hey! I don't have much experience with Blade & Statamic but from what I can tell from the documentation & from a brief conversion on Discord is that you can't use any of Simple Commerce's "form tags" in Blade because they need to have 'content' inside them (for example: the HTML that goes in the middle of the start & end tags) {{ sc:cart:addItem }}
<input type="hidden" name="product" value="{{ id }}">
<input type="number" name="quantity" value="2">
{{ /sc:cart:addItem }} I've commented on an open Statamic feature request, statamic/ideas#802 as hopefully it's something that can be added in future. Anyway, as a workaround, I think you have two options.... 1. Use Antlers for the 'add to cart form' You don't have to stick with one templating language for your entire site, you can mix and match. So, on your product page where you need to add the 'add to cart form', Then in the Antlers file, you can use Simple Commerce's "form tags". 2. Create the Simple Commerce's "form" tags essentially wrap your HTML from inside the tag inside a However, if you need to, you can hard code the code for these forms yourself. For example, my <form method="POST" action="http://sc-sandbox.test/!/simple-commerce/cart-items">
<input type="hidden" name="_token" value="the_csrf_token">
<input type="hidden" name="_redirect" value="a_big_encrypted_string" /> <!-- This is optional. With the setting I talk about below set to true, you can make the value of this a relative URL, like "/cart" -->
<input type="hidden" name="_error_redirect" value="a_big_encrypted_string" /> <!-- This is optional. With the setting I talk about below set to true, you can make the value of this a relative URL, like "/cart" -->
<input type="hidden" name="_request" value="a_big_encrypted_string" /> <!-- This is optional. With the setting I talk about below set to true, you can make the value of this the name of a Form Request in your App\Http\Requests folder (for validation) -->
<input type="hidden" name="product" value="product-id">
<input type="number" name="quantity" value="2">
</form> You can find out what each of the different "form tags" produce by using the Antlers Tags somewhere on the site (or in a blank site using the starter kit), then adjusting it for your case. Also... if you go down this route, you will need to set Hopefully that all made sense - sorry for the bad news & that I just threw a wall of text at you. Hopefully some of that will lead you to find a solution! Let me know if you have any further questions! |
Beta Was this translation helpful? Give feedback.
-
Ahh including antlers templates from blade will work just fine. Thanks so much for point that out. Thanks for taking the time on on this and for all the work you do! @duncanmcclean |
Beta Was this translation helpful? Give feedback.
-
Proper Blade support for Simple Commerce is in the pipeline - see #792 👀 |
Beta Was this translation helpful? Give feedback.
Hey!
I don't have much experience with Blade & Statamic but from what I can tell from the documentation & from a brief conversion on Discord is that you can't use any of Simple Commerce's "form tags" in Blade because they need to have 'content' inside them (for example: the HTML that goes in the middle of the start & end tags)
I've commented on an open Statamic feature request, statamic/ideas#802 as hopefully it's something that can be added in future.
Anyway, as a workaround, I think you have two options....
1. Use Antlers for the 'add to …