referencing local style sheet, only if it exists...

Nando's Avatar

Nando

09 Mar, 2016 04:39 PM

I'm using the same template/formats for multiple sites but some need to be bit more custom than others... at first I was using:

#if ($currentPageSiteName == SITENAME")2<link href="style.css" rel="stylesheet" type="text/css"/>#end

which works fine but I would have to do that for each site that has a local style sheet... I'd like to check if a local style sheet exist then reference it, something like:

#set($localstyle  = $_.locateFile('/style.css', $currentPageSiteName))
#if($localstyle)<link href="style.css" rel="stylesheet" type="text/css"/>#end

but that doesnt work... is what I'm trying to do possible?

as always, thanks in advance!

  1. 1 Posted by Nando on 09 Mar, 2016 06:44 PM

    Nando's Avatar

    got it!

    #set($localstyle  = $_.locateFile('style.css', $currentPageSiteName))
    #set($cpagepath = ${currentPage.path})
    #if($cpagepath.contains("/"))
    #set($localdir = $cpagepath.substring(0, $cpagepath.lastIndexOf('/')))
    #set($localdircss = $localdir + ("/style.css"))
    #end
    #set($localstyle2  = $_.locateFile($localdircss, $currentPageSiteName))
    #if($localstyle || $localstyle2)<link href="style.css" rel="stylesheet" type="text/css"/>#end
    

    had to do it this way bc we have different sites on the root of Sites and sites inside directories of sites... thoughts? suggestions?

  2. 2 Posted by Ryan Griffith on 10 Mar, 2016 02:47 PM

    Ryan Griffith's Avatar

    Thank you for following up. I am glad to hear you were able to come up with a solution.

    Another possible solution is to apply a specific Metadata Set to these CSS files and use the Query API to obtain all files using that Metadata Set and sort them by path. You could then loop over those files (if any were returned) and match the file path to the calling page (to handle the nested issue).

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  3. Ryan Griffith closed this discussion on 10 Mar, 2016 02:47 PM.

  4. 3 Posted by Ryan Griffith on 10 Mar, 2016 02:47 PM

    Ryan Griffith's Avatar

    Thank you for following up. I am glad to hear you were able to come up with a solution.

    Another possible solution is to apply a specific Metadata Set to these CSS files and use the Query API to obtain all files using that Metadata Set and sort them by path. You could then loop over those files (if any were returned) and match the file path to the calling page (to handle the nested issue).

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM