Jump to content

change url of css file based on file availablility


ravenquork

Recommended Posts

Currently the URL to the  sites css file is this:

 

<link rel="stylesheet" media="screen" href="{$insUrl}themes/{$CalendarInfo['css']}" type="text/css" >

where $insUrl is a local link.

I would like to allow users to optionally link to an external css file. My thinking is to optionally use either the existing URL to a local css file or a user supplied URL to a remotely hosted css file

so if I define:

$insUrl is the URL to a local themes/local.css file

$insUrlcss is the URL to either remote.css or local.css files

$insUrlcssremote is the URL to a remotely hosted css file

$remotecss  is the name of a remote css file

{$CalendarInfo['css'] is a local css file

 

Currently I have:

href="{$insUrl}themes/{$CalendarInfo['css']}"

 

In English, I would like to first use:

href="{$insUrlcssremote}/{$remotecss}"  (A link to to a remote css file) 

But, if remote.css  doesn't exist, use the original link

href="{$insUrl}themes/{$CalendarInfo['css']}"  (A link to to a local css file)

 

My thinking is to use something like

 

href="{$insUrlcss}"

 

First Check if {$remotecss} exists

 

if remote.css exists

then use it

{$insUrlcss} = {$insUrlcssremote}/{$remotecss}

href="{$insUrlcss}" becomes href="{$insUrlcssremote}/{$remotecss}"

 

if $remotecss doesn't exist

then fail gracefully to the local.css file

insUrlcss = $insUrl}themes/{$CalendarInfo['css']

or in other words

href= "{$insUrlcss}" becomes href="{$insUrl}themes/{$CalendarInfo['css']}"

 

Since I am a total noob at php, I need help in actually writing this piece of code

 

 

Link to comment
Share on other sites

<?php
  if($remotecss){
    $insUrlcss = "{$insUrlcssremote}/{$remotecss}";
  }else{
    $insUrlcss = "{$insUrl}themes/{$CalendarInfo['css']}";
  }
?>
<link rel="stylesheet" media="screen" href="{$insUrlcss}" type="text/css" >

 

or shorthand:

<link rel="stylesheet" media="screen" href="<?=($remotecss)?"{$insUrlcssremote}/{$remotecss}":"{$insUrl}themes/{$CalendarInfo['css']}"?>" type="text/css" >

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.