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

 

 

<?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" >

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.