Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selective usage of shortcode not working #34

Open
bernhardh opened this issue Jun 19, 2018 · 4 comments
Open

Selective usage of shortcode not working #34

bernhardh opened this issue Jun 19, 2018 · 4 comments

Comments

@bernhardh
Copy link

Hello,

first of all: Thanks for your great work!
I have the following issue (bug?):

I have the following controller:

Route::get('shortcode', function(){
    return view('test.shortcode')->with("code", '[b class="bold"]Bold text[/b]');
});

Case 1 - As expected
When I use the variable $code in the template like:
{{ $code }}
it works as expected - I only get the raw string as a result:
[b class="bold"]Bold text[/b]

Case 2 - As expected
When I use the variable $code with the compile comand in the template like:
{{ \Shortcode::compile($code) }}
it works as well as expected - I get the (escaped) parsing result:
<strong class="bold">Bold text</strong>
Using it with unescaped blade:
{!! \Shortcode::compile($code) !!}
I get
<strong class="bold">Bold text</strong>

Case 3 - Weird
But when I combine both versions, the result is weird.

{{ $code }}<br>
{{ \Shortcode::compile($code) }}

This is the result:

<strong class="&quot;bold&quot;">Bold text</strong><br>
&lt;strong class=&quot;bold&quot;&gt;Bold text&lt;/strong&gt;

WTF? Why gets the first line ({{ $code }}<br>) parsed and why is the result wrong (&quot;bold&quot;)?

@professorhaseeb
Copy link
Contributor

your Case 1 works if you add ->withShortcodes(); at the end.

Route::get('/test', function(){
    return view('test')->with("code", '[b class="bold"]Bold text[/b]')->withShortcodes();
});

Result: https://prnt.sc/jyi07l

@bernhardh
Copy link
Author

Thats not the problem, because case 1 is not expected to work, so its ok, that it doesn't work. The problem is the weird behavior of case 3.

@professorhaseeb
Copy link
Contributor

test.blade.php

{{$code}}
<br>
{!! \Shortcode::compile($code) !!}

web.php

Route::get('/test', function(){
     return view('test')->with("code", '[b class="bold"]Bold text[/b]');
});

Result: http://prntscr.com/jz3s82

Try using \Shortcode::enable(); in your controller or ->withShortcodes();

@adnedelcu
Copy link

I think what @bernhardh wants to say is that he doesn't want the first line ({{ $code }}<br>) to be parsed, while the second one should ({{ \Shortcode::compile($code) }}).

This is also something we've been facing ourselves. Is there a way to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants