Make links in included files global (laravel) - laravel

I have a header file that links to the user dashboard that displays on all pages on my site, but if I access the link from a page such as localhost/pages/page, I have to put href="../dashboard". If I am on the root directory (such as localhost/page) then using href="dashboard" works.
Is there a simpler way than changing the directories on every single page so I can just use href="dashboard" on all pages?

Use url() helper method:
<link rel="stylesheet" href="{{url('/dashboard/plugins/bootstrap/css/bootstrap.min.css')}}">

Related

How to use single css in a multi-tenant application

i'm developing a multi-tenant application with laravel & livewire.
I've a bootstrap template mounted such as a laravel project and i've integrated this template in my project.
For how the template is built, when I am on the localhost:8000/... views I get the correct rendering of the template, while when I go to the domain of a tenant, example: tenant.localhost:8000/... I completely lose the template.
I noticed that in resources/layout/default.blade to load all css and js there is a for loop that takes the css from the configuration file and loads them into the page
{{-- Global Theme Styles (used by all pages) --}}
#if(!empty(config('dz.public.global.css')))
#foreach(config('dz.public.global.css') as $style)
<link href="{{ asset($style) }}" rel="stylesheet" type="text/css"/>
#endforeach
#endif
using asset($style) when I go to the tenant domain, it looks for the css in a location that does not exist (the css are under localhost).
I thought of inserting an if-else inside the foreach loop in order to check the domain in the asset($style) and make sure that when in the tenant domain the css are searched as if we were in the localhost domain.
It's a good idea? do you have any advice or suggestions?
Now the asset location is changed for each tenant. You could 'hardcode' it.
Something like:
<link href='{{ env('APP_URL') }}/location/style.css'>
Another solution is to use the url() helper function instead of asset(), since it would generate an absolute path for the assets, this way you can use it in the same way as you use asset() function

Including page layout to Laravel project

I was supplied with a custom layout for the login page of my Laravel project.
When I opened login.html file, which represents the layout for that specific page I saw such links
<!-- Base Css Files -->
<link href="assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<link href="assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
...
So I figured that I only need to copy the assets folder, which came with the template (there are all needed bootstraps, jqueries and whatnot) to my projects app\resources\assets directory
Now, when I copied the code from login.html into my login.blade.php view and copied the templates' assets folder to app\resources\assets it doesnt work. It only displays naked html code when I open the page.
What am I doing wrong in linking the assets folder?
The resources folder is (like the name says) for the resources.
If you don't want/need to build/compile/min your scripts, then just put them in the public folder, so you can access them from your template.
In your case
public/assets/libs...
In order to access assets, you have two ways to approach it. Either using Elixir/gulp or to use direct access.
Gulp is a node.js application that reads your assets files, whether JS, CSS, Coffee, etc...and combine them in single files. Gulp reads the files defined in the gulpfile.js, and you can access the output files in your blade file using elixir().
You can read more about Elixir here.
In your specific case, you can just place the files under the public/ directory. So Laravel treats public as the root directory, and if you want to read the file assets/css/foo.css just place the file in public/assets/css/foo.css

Laravel 5 helper function asset different domains

In Laravel 5.0, I am using the helper function asset to show where different assets are ( css, js images etc. ). I am building a platform that shows different information depending on the url which means I cannot bind the asset to a url. I know in config/app.php it has 'url' => 'http://localhost' but I cannot change that because the url will not always be the same. Is there a way to set this up to handle the domain changing within the same application?
Assuming your assets are always going to be in the same relative path from the root of the site (regardless of the domain), you should just be able to output the URL to various assets as a relative URL. So, for example, if in your blade template you had something like:
<link rel="stylesheet" href="{!! asset('css/style.css') !!}">
you could replace it with a relative URL like this:
<link rel="stylesheet" href="/assets/css/style.css">
This should resolve correctly regardless of what domain you're on, and should also be fetched via HTTPS in the case that the user is on a secure page.
If you need something more complicated, you might consider setting a session('domain') variable or something that would be accessible from a global scope that could then be used to generate links to assets like:
<link rel="stylesheet" href="http://{{ session('domain') }}/assets/css/style.css">
If none of these work, then your situation is probably complicated enough that you'll need to provide us some more code before we can offer workable solutions.

Is there a way in Total.js to add to #{head} from a view?

I'm using total.js and wanting to add a page-specific CSS link tag to a page's HTML <head> from within a view, rather than coding it into the route's controller.
I've tried to use #(head(css('page.css'))} but that results in a server error. Using #{css('page.css')} prints out the CSS link tag as part of the #{body}. Yet, the #{meta('Page Title')} directive is able to direct its output to the <head> section of the page.
Am I missing something or is it just not possible in this version of total.js?
Try to add #{head('/css/page.css')}.

Joomla - Insert .js and .css files into a single Joomla article?

Is it possible for a single page on a Joomla website to include it's own custom .js and .css files?
I basically would like to add two custom javascript and css files for a particular page. I don't want these files included into any other Joomla pages.
Any suggestions would be appreciated.
Thank you
Try using a custom code extension such as JUMI. It is designed exactly for this purpose.
From the description: With Jumi you can include php, html, javascript scripts into the modules position, articles, category or section descriptions, or into your own custom made component pages.
The solution from Soygul wont result in proper HTML since these statements / includes belong to the HTML header.
Use : http://extensions.joomla.org/extensions/edition/custom-code-in-modules/11936
This plugin allows inserting material into the head section of your Joomla web site.
You can then use the menu assignment functionality to just add that to certain pages.
Its quite easy to write a simple module like that for yourself - but since this seems already available go with that one. If it doesn't fit your needs :
You just need an "empty / hello world" module with these two statements :
( http://docs.joomla.org/Creating_a_Hello_World_Module_for_Joomla_1.5 )
( http://docs.joomla.org/Adding_JavaScript_and_CSS_to_the_page )
// Add a reference to a Javascript file
// The default path is 'media/system/js/'
JHTML::script($filename, $path, $mootools);
// Add a reference to a CSS file
// The default path is 'media/system/css/'
JHTML::stylesheet($filename, $path);
I'm not a big fan of adding new extensions to Joomla unless absolutely necessary. If you do, make sure it's not on Joomla's list of vulnerable extensions, first. Each third-party extension/plugin you add is just one more potential back door for hackers.
To add your own custom CSS for a page, you can either edit your template's master CSS file, or just create your own and link it to the project. Here's how you'd do that:
First, figure out how your CSS files are being called. The actual file names will surely differ from my example, based upon the template you're using, but let's look at the Joomla SYSTEM template, which is located in templates/system. The index.php file controls everything, so open it up and you'll find this line:
<?php
include dirname(__FILE__).DIRECTORY_SEPARATOR.'component.php';
?>
Open component.php and you'll see some code that looks like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
You can see the call to include a CSS file in the 3rd line. All you need to do is add another line calling a CSS file you create. Create a new file called /templates/system/css/custom.css (or whatever you like) and rewrite the code segment in component.php to look like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/custom.css" type="text/css" />
Now you can just code out your own CSS in the new custom.css file you created. You can do this with any template system from RocketTheme or YooTheme just as easily. In fact, if you use one of their templates, they probably already have a custom.css file that you can simply add your own code to. Just be aware if you do it that way and then later update the template, you'll lose your code additions. That's why I prefer writing my own file. You can probably do something very similar to include custom JS code, but I tend to avoid JS like the plague, so someone else will have to address how to link out to a custom JS file.

Resources