Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

SkinChange

Summary: change skin via query or cookie setting
Version: pmwiki-2.3.37
Status: Stable
Prerequisites: pmwiki-2.0
Maintainer: Petko (original author: Pm)
Categories: Skins Layout PHP72
Discussion: SkinChange-Talk
Users: (view / edit)

How can I allow users to change their skin based on a query parameter or cookie setting?

Note, PmWiki 2.2.127 or newer already contains this feature, so you don't need to download a file and use an include_once() line. If you have previously installed this recipe please remove that line. The other configuration variables still apply, see below.

Description

The feature enables query parameters of the form

  • "?skin=", or
  • "?setskin="

to be added to a page url to allow users to view pages with a different skin.

  • The ?setskin= query stores a cookie on the browser that causes a different skin to be used for all subsequent pages.
  • The ?skin= only changes skin for the currently displayed page.

In config.php place

$EnableAutoSkinList = 1;

To restrict browsers to specific skins, create a $PageSkinList array mapping values for ?skin= or ?setskin= to the skin to be used:

$PageSkinList = array(
    'pmwiki' => 'pmwiki',
    'classic' => 'myclassicskin',
    'jh' => 'jhskin');
include_once('cookbook/skinchange.php'); # Only for PmWiki 2.2.126 or older

These example links set the skin just for viewing a single page:

These example links store a cookie in your browser so that all future visits to this site will show that skin.

If $EnableAutoSkinList is also set, then entries in $PageSkinList take precedence. If a browser requests a skin that isn't available, then PmWiki defaults to the skin already defined by $Skin.

By default, the setskin cookie that is created will expire after one year. You can set it to expire at the end of the browser session by setting $SkinCookieExpires=0;

For wiki-code that will automatically generate a list of available skins, see SkinList.

Skinchange and Wiki Farms

Like most other PmWiki customizations, instructions from more specific files override those from less specific files, in a chain like this:

  • farmconfig.php
  • field's config.php
  • GroupName.php
  • GroupName.PageName.php

Enable skinchange farmwide

  1. Just follow the directions above, but put the code in your farmconfig.php

Override skinchange for a particular field

  1. put $Skin = 'your_skin'; in the field's config.php

Centrally manage the skin list, set default skin per field, and allow user to choose skin per field

  1. put your skins array in your farmconfig.php
  2. to set a field's default skin, put $Skin = 'your_skin'; in the field's config.php
  3. to enable skin changing for a field, define $EnableAutoSkinList or $PageSkinList in the field's config.php. Users can change skins for this field without affecting the skin choices for other fields.

Centrally manage the skin list, set default skin per field, and allow user to choose skin for entire farm

  1. put your skins array in your farmconfig.php
  2. enable skin changing for the farm by putting define $EnableAutoSkinList or $PageSkinList in farmconfig.php
  3. to set a field's default skin, put SDV($Skin, 'your_skin'); in the field's config.php. If the user has deliberately changed skins, this will be overridden by their farm-wide choice.

Automatic Browser Based Skin Change

You can also perform a skin change based on browser detection. Refer to WikiOnPDA.

Notes

To use this script for PmWiki 2.2.126 or older, place skinchange.phpΔ into the cookbook directory of your installation (newer PmWiki versions already contain the feature and you don't need to download and include the file). To allow browsers to use any skin already loaded into the skins directory, simply set $EnableAutoSkinList and include the recipe:

$EnableAutoSkinList = 1;
include_once('cookbook/skinchange.php'); # Only for PmWiki 2.2.126 or older

The recipe should work with PHP 4 - PHP 7 on all PmWiki 2.2.x versions but PmWiki versions 2.2.105 or later can use secure cookies to store the visitors' preferences if this is desired.

Release notes

  • 20200323 : added to core for PmWiki 2.2.127, any more recent changes will appear at PmWiki:ChangeLog.
  • 20171115 : Fix $RecipeInfo bug reported by Simon. Update to use pmsetcookie() if available from PmWiki 2.2.105.

Contributors

  • Script maintained by Petko.
  • Pm, original script (25-Feb-2004)
  • Pm, updated for PmWiki 2 (9-Nov-2004)
  • mhg?, Comments and examples (20-Jan-2005)

Comments

Note: after PmWiki 2.2.x beta, pages in headers, footers, sidebars needs to use the * to reference the page variable of the page calling the sidebar/header/footer included files: [[{*$Name}?skin=marathon]] etc. This is only used on pages that will be included in other pages when you want to use the variables from the current page, otherwise the $Name is Group/SideBar or Group/GroupHeader

Question:
How do I create two links on the Side Bar (popupmenu) of Simple skin, that change the skin for the user, with the ?setskin= option ?
One link might say "Desktop View" and the other "Mobile View".
Preferably, the current page gets reloaded, instead of opening another page.
nikos? February 08, 2019, at 02:58 PM

You can add in the sidebar something like [[{*$FullName}?setskin=skin1|Desktop view]] [[{*$FullName}?setskin=skin2|Mobile view]]. The variable {*$FullName} always means the current page. --Petko February 08, 2019, at 04:30 PM

It works! Thanks.
nikos? February 13, 2019, at 06:41 PM


Question : skinchange is useful but it adds something like ?n=Site.Science?skin=simple to the URL.

How can i avoid the ?skin=simple

To change the skin for all users, set in config.php $Skin='simple';. To set the skin for your browser, for your session only, go to ?setskin=simple once then the browser will remember your preference for all other pages. To only view a single page with a specific skin, go to ?skin=simple. --Petko November 15, 2017, at 03:35 PM

User notes : If you use, used or reviewed "SkinChange", you can add your name. These statistics appear in the Skins listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on March 20, 2024, at 02:59 AM