Created
January 10, 2014 12:53
-
-
Save noxify/8351451 to your computer and use it in GitHub Desktop.
Example to use the laravel4-theme package from teepluss
Github: https://github.com/teepluss/laravel4-theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //app/controllers/BaseController.php | |
| class BaseController extends Controller { | |
| /** | |
| * Setup the layout used by the controller. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| // Using theme as a global. | |
| $this->theme = Theme::uses('default')->layout('default'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //vendor/<vendorname>/<packagename>/src/controllers/PackageController.php | |
| namespace vendorname\PackageName; | |
| class PackageController extends \BaseController { | |
| public function __construct() { | |
| parent::__construct(); | |
| } | |
| public function index($year = null, $month = null) | |
| { | |
| //your code | |
| //overwrite existing variables in the theme | |
| $this->theme->set("keywords", "My Custom Meta Keyword"); | |
| $this->theme->set("title", trans('package_name::site.title')); | |
| try { | |
| //check the themes and views directory | |
| $this->theme->scope(\Config::get('package_name::index_view'), $viewData)->location(); | |
| //view exists in the theme and/or views directy | |
| return $this->theme->watch(\Config::get('package_name::index_view'), $viewData)->render(); | |
| } catch( \InvalidArgumentException $e ) { | |
| //view does not exists in the theme and views directory | |
| //we have to use the view from the package directory | |
| //this is only a fallback :) | |
| return $this->theme->load('vendor.vendorname.package_name.src.views.'.\Config::get('package_name::index_view'), $viewData)->render(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment