Create Drupal 8 one off page that overrides html.html.twig? - php

I have a client with a Drupal 8 running site. They want to one URL of the site to render very different from the rest of the site. I have created a module. I need just a single route to override html.html.twig. I want to strip out the majority of the stuff the site theme is loading. I am sort of able to get it to work but it seems to apply to every page which effectively breaks the site. This url /site/mynewapp would use completely different layout and html from the rest of the hundreds of other pages. Basically this is a static site within an existing Drupal 8 instance. How do I conditionally load a custom html.html.twig, page.html.twig, and node.html.twig only when /site/mynewapp is requested? This is a ReactJS app basically that should only run on a single page of the site. I realize this isn't the ideal architecture. I have asked the client to run the app separately on nodejs but they insist it must be within their existing Drupal instance. The React app looks nothing like the rest of site. Does anyone have experience doing something like this. I have custommodule.routing.yml with the route defined and a controller method that bolts on the javascript lib. This works but it seems to load on every page which can't happen.
public function overview()
{
$build = [];
$build['#attached']['library'][] = 'mymodule/mylibrary';
$build['#markup'] = '<div id="root"></div>';
return $build;
}
and in the module file
function mymodule_theme_registry_alter(&$theme_registry)
{
$theme_registry['html']['path'] = drupal_get_path('module',
'mymodule') . '/templates';
}
this is loads the html.html.twig for every page in the site essentially breaking it.
Any suggestions here?

You don't need a module to override the twig template.
You just create the files in your theme folder with the right name and you are ready to go.
To override html.html.twig you have to create something like html--mynewapp.html.twig
To override page.html.twig you have to create something like page--mynewapp.html.twig
To override node.html.twig you have to create something like node--mynewapp.html.twig
You clear the cache and the new template will load when you visit these pages.

The react mount node module will embed an empty div to mount your React page within your Drupal site in the content region.
If you truly want a completely separate React app inside of Drupal, you can just build it in a subfolder of your site. Like /myapp and put the whole build in there.

Related

Angular routing under wordpress site

I have a WordPress site where one of the pages that WordPress serve is an SPA based on AngularJS. The Angular-app uses html5mode so that I can browse to http://localhost/79133/71 and I'm still showing index.html. Now I want to deploy this to my WordPress site so that one of the pages under WordPress (the main page) is my SPA. However, if I browse to http://example.com/79133/71 WordPress will try to find the page with the permalink 79133/71 and won't understand that the main page should be served. How can i configure WordPress so that these new "routes" will be pointing to the first page?
I'm not an expert on WordPress, but in order to get html5mode to work in angular:
Any route starting with /your_spa needs to serve the main page (index.html) of your app.
You must ensure that any resources referenced in your spa (for example, /assets/themes/theme.css) needs to point to the correct location, even if your location url is your_spa/your/spa/page. This means no relative paths unless you use the base tag.
Here's a tutorial on how to configure the router in wordpress. I don't use wordpress so I'm sorry that I
It seems like a lot of trouble, and I would just use the default hash routes if possible.
I had the same basic issue, and solved it. Your situation is slightly different but I think you need something like:
function spa_rewrite() {
add_rewrite_rule('79133/71', '/', 'top');
}
add_action('init', 'spa_rewrite');
In practise you'll need to use some regex to make this more flexible

Codeigniter Website is not responding

I am using the codeigniter framework for my website.
Previously my website was working fine. But a few days ago I made some changes in code (I add some files for cron job).
When I made these changes my website is not responding it is continuously connecting to the server.
I am using the stencil with the codeigniter.
When I use the ordinary codeigniter view function:
$this->load->view('view_name');
It was working but as I am using stencil paint:
$this->stencil->paint('view_name'); // its not working.
Website URL: http://blogsetu.com/
I would recommend you to read the documentation again there is something you might have missed we can't say any thing without viewing the full source code
However I think you missed to set a layout
from http://scotch.io/docs/stencil
Bare Minimum to Get Started Set a Layout in your Controller
You always will need to set a layout. This is required for Stencil.
Layouts are located in "/views/layouts/". To learn more, visit the
docs about layouts.
$this->stencil->layout('default_layout'); Set and Load a View with
the "paint()" function
To set and load a view you will initiate the "paint()" function. This
function is the equivalent to "$this->load->view($view)" in
Codeigniter.
To learn how to bind data to the view, please click here.
These are located in the "Pages" folder inside of the views folder.
The HTML from these pages are made available in the layout as the
$content variable.
$this->stencil->paint('example_view');

render a php application inside Joomla article

I have a folder containing a php booking system,that i want to render as un article and add it to the main menu of the site.
The solution that i end with, is to use the joomla URL Wrapper. But it brokes my design as it render it inside an iframe.
Is there another way to do that?
Use Jumi, it includes PHP files into articles, without iframes.
Usage:
{jumi [path/to/file.php]}
Jumi website
That requires an integration work. At least you'd rather think of the way to give some Jooml Component wrapper to your booking sysytem. which at least involves creating a com_yourcomname folder, and a yourcomname.php that will dispatch your actions to the actions of the booking component and, perhaps, filter the urls in the output so that they match the Joomla url building convetions. If do this properly, your app will appear as a page content (not an article)

Changinging Joomla template according to the url open in the browser, how?

I am asking if is it possible do the following thing using Joomla
I have 2 different URL, something like: www.stupidname.com and www.seriousname.com
If the user open stupidname.com by his browser will open the website having a stupid template
If the user open seriusname.com by his browser will open the website having a serious template
The website and the content are the same...should only change the template according to the url open in the browser
Do you have some ideas about how to do this thing?
Thanks
Andrea
I've done this before making elements of a template conditional based on the domain name, and that can work well. I suppose you could extend the same logic to change the template.
Perhaps you could add a conditional to both template's index.php to change the template. Perhaps something like...
if ( substr_count( $_SERVER['HTTP_HOST'], "silly") ) {
$GLOBALS["mainframe"]->setTemplate = "silly_template_name";
} else {
$GLOBALS["mainframe"]->setTemplate = "serious_template_name";
}
...I've not tested this, but I think in principle it should work fine, though it might depend on which Joomla version you have.
There are, as saji89 pointed out, plenty of good multi-site extensions and that'd be an ok solution too.
From my personal experience with Joomla I can advise you to use the component Virtual Domains (http://extensions.joomla.org/extensions/core-enhancements/multiple-sites/7557) you can add the domains which you redirect to the main site where Joomla is installed and it this component you assign them the template you want.
I can confirm the functionality on Joomla 2.5 latest update with usage of around 5+ different Virtual Domains on one Joomla installation.
Some possible downsides i want to mention:
SEO links can get sometimes messy, you need to play with some SEO component and its settings
its better to use same structure and components for boths side its easier because otherwise the administration gets messy but its possible
the user which register on one website has automatically account on all of them because its one Joomla

Test custom header in Drupal before publishing

I'm quite new to Drupal and want do some editing of the header. I want a custom toolbar to appear on every page. I've already created that toolbar in a file called toolbar.php. It has a layer which is fixed and will appear on top of every page.
How do I include the toolbar.php in the header template of drupal?
The toolbar refers to $user which is a global Drupal variable and I want to test toolbar.php before publishing it to the site. Is there anyway I can do that?
Regards,
Dasith
Of the two methods above the first is easier if you understand the basic idea of html and CMS templates, the second will be easier if you are a programmer.
First thing to check is that you really need to do this! Can't you restyle one of the existing menus (Primary or secondary) to do this - will make your life (and anyone who works on the site in the future) a lot easier.
The other thing you can do is look into adding an output region, basically something where you put the php into a drupal friendly format and then effectively do a 'drupal print'. This is how the toolbar, search box etc are done. You still need to alter the templates as above.
Yes for sure. If you want to have the html produced by your function/file appear on every page of the site then you will need to over-ride the page.tpl.php file in the theme you are using and essentually add the html to that file.
To gain access to the $user variable, just declare it in your script.
global $user;
open page.tpl.php file in a code editor and save as page-front.tpl.php (with two dashes if you are using Drupal 7.. one dash with Drupal 6) and upload it to your theme's directory. Clear your cache by going to configuration->Performance->Clear All Cache. Then referesh the page. Now your homepage is using page-front.tpl.php as it's template file. Every page will need its own template file. The page machine name comes after the hyphen so the user page template uses page-user.tpl.php. You can edit it as you want. The proper way to really do this is to use hook_theme() to pass variables to the template file. One variable could be the html which creates your custom header.
See also http://drupal.org/node/457740 Beginners Guide to over riding theme output

Categories