Download the PHP package vendi-advertising/vendi-template-router without Composer
On this page you can find all versions of the php package vendi-advertising/vendi-template-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vendi-advertising/vendi-template-router
More information about vendi-advertising/vendi-template-router
Files in vendi-advertising/vendi-template-router
Package vendi-template-router
Short Description WordPress template router
License MIT
Homepage https://github.com/vendi-advertising/vendi-template-router
Informations about the package vendi-template-router
README
The goal of this plugin was to better override WordPress's routing engine in a more explicit and controlled manner. There are times when you want the full power of WordPress's CMS backend but you want to take complete control of the rendering. Usually this scenario pops up most when you are developing an application instead of just a website.
At the time that this plugin was created the REST API was just entering beta and the work on the rewrite engine wasn't spoken of yet. (Hopefully that's coming soon, though!)
The general use-case for this plugin is for URL "folders" that you want to redirect to your own template folder based on name. For instance, if you want everything at https://www.example.com/app/
to go to your own application folder (which doesn't even need to live in the web root).
This plugin can be installed as a normal plugin however it is recommended that you actually install this as an MU plugin.
To use this plugin you just need to register your route:
\Vendi\Shared\template_router::register_context(
<context_name>,
<url_folder>,
<template_location_root>,
<magic_page = 'page'>,
<template_subfolder = 'templates'>
);
- <context_name>
- Arbitrary string name that represents URLs relative to <url_folder>.
- If you want to ask the
template_router
to generate URLs later you'll need this.
- <url_folder>
- Arbitrary valid URL string that represents the "folder" that your application is served from.
- <template_location_root>
- The absolute path that requests to <url_folder> will be passed to.
- <magic_page>
- When passing the requested route to your template this query string variable will be used.
- Make sure that your app does not depend on this value.
- This value is optional and defaults to "page".
- This parameter is poorly named and really should be "internal_query_string_key" or something.
- <template_subfolder>
- The subfolder relative to <template_location_root> that holds the templates for this route.
- This value is optional and defaults to "templates"
Example
For a general application called Test
that you want to have all routes start with test
and with the WordPress install at /var/www/wordpress-root-folder/
and with templates living in /var/www/wordpress-root-folder/templates/
you would register your context using:
\Vendi\Shared\template_router::register_context(
'Test',
'test',
'/var/www/wordpress-root-folder/'
);