<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Package Archives : vedmant.com : coding blog</title>
	<atom:link href="https://vedmant.com/tag/package/feed/" rel="self" type="application/rss+xml" />
	<link>https://vedmant.com/tag/package/</link>
	<description>Sharing my personal experience in web development</description>
	<lastBuildDate>Tue, 23 Apr 2019 13:54:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8</generator>
	<item>
		<title>Laravel Shortcodes</title>
		<link>https://vedmant.com/laravel-shortcodes/</link>
					<comments>https://vedmant.com/laravel-shortcodes/#comments</comments>
		
		<dc:creator><![CDATA[vedmant]]></dc:creator>
		<pubDate>Tue, 23 Apr 2019 13:41:41 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Composer]]></category>
		<category><![CDATA[Package]]></category>
		<category><![CDATA[Shortcodes]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://vedmant.com/?p=241</guid>

					<description><![CDATA[<p>WordPress based Shortcodes for Laravel 5.x with shared variables, debugbar integration, flexible configuration and other useful features. Github: https://github.com/vedmant/laravel-shortcodes﻿ Build powerful and simple layouts using shortcodes in the content or views like this: Installation Via Composer This package supports Laravel Auto-Discover and will be discovered automatically. For Laravel version before 5.5 please add the Vedmant\LaravelShortcodes\LaravelShortcodesServiceProvider::class &#8230; <a href="https://vedmant.com/laravel-shortcodes/" class="more-link">Continue reading <span class="screen-reader-text">Laravel Shortcodes</span></a></p>
<p>The post <a href="https://vedmant.com/laravel-shortcodes/">Laravel Shortcodes</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>WordPress based Shortcodes for Laravel 5.x with shared variables, debugbar integration, flexible configuration and other useful features.</p>



<p>Github: <a href="https://github.com/vedmant/laravel-shortcodes" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/vedmant/laravel-shortcodes﻿</a></p>



<p>Build powerful and simple layouts using shortcodes in the content or views like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&#x5B;b]Bold text&#x5B;/b]
&#x5B;row]
  &#x5B;col md=8]
     &#x5B;posts_list types="post,gallery" show_tags="yes"]
  &#x5B;/col]
  &#x5B;col md=4]
     &#x5B;poll id="1"]
     &#x5B;user_info username="test_user" website="mywebsite.com" active="yes"]
     &#x5B;last_free_post title="Free Posts"]
  &#x5B;/col]
&#x5B;/row]
</pre></div>


<h2 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#installation"></a>Installation</h2>



<p>Via Composer</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$ composer require vedmant/laravel-shortcodes
</pre></div>


<p>This package supports Laravel Auto-Discover and will be discovered automatically.</p>



<p>For Laravel version before 5.5 please add the Vedmant\LaravelShortcodes\LaravelShortcodesServiceProvider::class to the providers array in&nbsp;<code>config/app.php</code>. And optionally &#8216;Shortcodes&#8217; =&gt; Vedmant\LaravelShortcodes\Facades\Shortcodes::class, to aliases.</p>



<h2 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#configuraton"></a>Configuraton</h2>



<p>Publish configuration.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
php artisan vendor:publish --tag=shortcodes
</pre></div>


<h2 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#usage"></a>Usage</h2>



<h3 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#shortcode-class"></a>Shortcode class</h3>



<p>Shortcode class should extend abstract \Vedmant\LaravelShortcodes\Shortcode class.</p>



<p>This packages adds&nbsp;<code>make:shortcode</code>&nbsp;artisan command:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
php artisan make:shortcode PostsListShortcode
</pre></div>


<p>It will generate a shortcode class in the&nbsp;<code>app/Shortcodes</code>&nbsp;folder by default.</p>



<h3 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#register-shortcodes"></a>Register shortcodes</h3>



<p>You can use AppServiceProvider boot method to register all needed shortcodes.</p>



<p>Using shortcode class:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
Shortcodes::add('b', BShortcode::class);
</pre></div>


<p>Using shortcode classes in array, preferable for lots of shortcodes:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
Shortcodes::add(&#x5B;
   &#039;a&#039; =&gt; AShortcode::class,
   &#039;b&#039; =&gt; BShortcode::class,
]);
</pre></div>


<p>Using closure:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
Shortcodes::add(&#039;test&#039;, function ($atts, $content, $tag, $manager) {
   return new HtmlString(&#039;&lt;strong&gt;some test shortcode&lt;/strong&gt;&#039;);
});

</pre></div>


<h3 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#rendering-shortcodes"></a>Rendering shortcodes</h3>



<p>By default this packages extends View to parse all shortcodes during views rendering. This feature can be disabled in the config file.</p>



<p>Also to enable / disable rendering shortcodes for specific view you can use:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
view(&#039;some-view&#039;)-&gt;withShortcodes(); // Or view(&#039;some-view&#039;)-&gt;withoutShortcodes();
</pre></div>


<p>To render shortcodes manually use:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
{{ Shortcodes::render('&#x5B;b]bold&#x5B;/b]') }}
</pre></div>


<h3 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#shared-attributes"></a>Shared attributes</h3>



<p>YOccasionally, you may need to share a piece of data with all shortcodes that are rendered by your application. You may do so using the shortode facade&#8217;s&nbsp;<code>share</code>&nbsp;method. Typically, you should place calls to share in the controller, or within a service provider&#8217;s boot method.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
Shortcodes::share('post', $post);
</pre></div>


<p>Then you can get share attributes in the shortcode class:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
$post = $this-&gt;shared(&#039;post&#039;); $allShared = $this-&gt;shared();
</pre></div>


<h3 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#comma-separated-values-array-attributes"></a>Comma separated values (array attributes)</h3>



<p>If you need to pass an array to a shortcode, you can pass values separated by comma:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&#x5B;posts_list ids="1,2,3"]
</pre></div>


<p>Then in render function you can parse this attribute using build in method:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
$ids = $this-&gt;parseCommaSeparated($atts&#x5B;&#039;ids&#039;]);
</pre></div>


<p>Edit configuration file as needed.</p>



<h3 class="wp-block-heading"><a href="https://github.com/vedmant/laravel-shortcodes#integration-with-laravel-debugbar"></a>Integration with Laravel Debugbar</h3>



<p>This packages supports Laravel Debugbar. Integration can be disabled in the config file if needed.<br></p>



<p>This project is fully free to use for any purpose and licensed under MIT License.</p>
<p>The post <a href="https://vedmant.com/laravel-shortcodes/">Laravel Shortcodes</a> appeared first on <a href="https://vedmant.com">vedmant.com :: coding blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vedmant.com/laravel-shortcodes/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
