2017 © Pedro Peláez
 

library tusk

Creates a plugin file to replacetext in a string with any php or html code

image

dnabeast/tusk

Creates a plugin file to replacetext in a string with any php or html code

  • Friday, July 8, 2016
  • by dnabeast
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Plugin code replacement in a string for Laravel

Problem

Your user needs to inject a chunk of code into a basic string using their CMS functionality. You want them to be able to set a Google map or text from a database but you don't want them to be able to run code., (*1)

Solution

Set up their code and allow them to reference it in their text string., (*2)

Installing

Add the dependency to your project:, (*3)

composer require DNABeast/tusk

Laravel 5.2:

After updating composer, add the ServiceProvider to the providers array in config/app.php, (*4)

DNABeast\Tusk\TuskServiceProvider::class,

Add the directory Plugin/lib to your App directory to contain your plugin files., (*5)

You may need to clear the view cache, (*6)

php artisan view:clear

Usage

In your blade file put your string inside the tusk directive., (*7)

@tusk('Your string [[- map -]]. Rest of String')

This writes a file in App\Plugins called map.php. If this file already exists nothing happens., (*8)

If your map.php file was this, (*9)

<?php echo '<iframe>Map</iframe>'; ?>

The blade file would replace [[- map -]] and output, (*10)

Your string <iframe>Map</iframe>. Rest of String

Use Case

  1. Your user can update their contact page with basic text but you don't want to allow iframes. You can still allow them to enter [[- googlemap -]] to inject the google map html required to embed a map., (*11)

  2. You have code that can spit out a list of links from the database. You also have basic pages on the site that allow the user to update their content and they can include the list code without having access to the actual code by simply entering [[- linklist -]]., (*12)

Potential pitfall

You plugin file can be all html but if it has php you need to echo the result. If you return it nothing will display. ie., (*13)

<?php
    $x = 34+65;
    return $x; // <- This wont work. You must echo it.
?>

The Versions

08/07 2016

dev-master

9999999-dev

Creates a plugin file to replacetext in a string with any php or html code

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dan Beeston

plugin blade