{source}

Shows the files behind a page as tabs, each coloured as highlight colours it - the code shown is the code that runs.

Text and formatting Single tags

Syntax

{source}
{source 'page', files='_lib/orders.php, www:orders.js'}
{source only='_tags/card.pad, www:card.js'}

Parameters

page
The page whose .pad (or .html) and .php come first - default the page being rendered.

Options

files
Files after the page's, a text with commas: a file of the application, or www: one in its www/ directory.
only
Those files alone, without the page's - the same kind of list as files=.

Description

{source} reads the template and the PHP of a page and shows them as tabs, each file coloured as {highlight} colours it. Because the code is read from the files that run, a page that explains itself can never show a sample that has drifted from what it does. Without a parameter it is the page being rendered - inside a {page}, the page that {page} renders.

files= adds more files after the page's, as a text with commas: a path of the application (_lib/orders.php, _tags/card.pad) or www: followed by a file of the application's www/ directory (www:orders.js). only= shows its files alone. A label carries data-side="server" for a file of the application and "client" for one under www/ - what runs on the server, and what the browser gets.

The tabs are a radio button and a label per file, then a panel per file, and work by CSS alone. The default look is written once a page under :where(), so the page's own CSS wins: style .pad-source, .pad-source > label and .pad-source-panel.

It follows the file rule of {highlight file=}: never a file outside the application or its www/ directory, under _config/ or a dotfile. Such a file, one that is not there, and a page that has neither a template nor PHP are errors.

Examples

The page itself

Without a parameter: the template and the PHP of the page asked for, as tabs.

Templateexamples/source/1-self.pad
<p>{$greeting}, {$visitor}!</p>
{source}
PHPexamples/source/1-self.php
<?php

  $greeting = 'Good morning';
  $visitor  = 'Ana';

?>
Resultopen alone

Good morning, Ana!

{meta title='The page itself', about='Without a parameter: the template and the PHP of the page asked for, as tabs.'}
<p>{$greeting}, {$visitor}!</p>
{source}
<?php

  $greeting = 'Good morning';
  $visitor  = 'Ana';

?>

Another page and more files

The first parameter names the page whose template and PHP come first; files= adds a file of the application.

Templateexamples/source/2-files.pad
{source 'examples/source/1-self', files='_lang/en.json'}
Resultopen alone
{meta title='The page itself', about='Without a parameter: the template and the PHP of the page asked for, as tabs.'}
<p>{$greeting}, {$visitor}!</p>
{source}
<?php

  $greeting = 'Good morning';
  $visitor  = 'Ana';

?>
{
  "trans.cart.title": "Your <em>shopping</em> cart",
  "trans.cart.checkout": "Go to checkout",
  "trans.cart.items": "Your cart is empty|One item in your cart|%d items in your cart",
  "trans.greeting": "Hello :name, welcome back to :place."
}

Chosen files alone

only= shows those files and leaves the page's own out.

Templateexamples/source/3-only.pad
{source only='examples/source/1-self.php, _lang/en.json'}
Resultopen alone
<?php

  $greeting = 'Good morning';
  $visitor  = 'Ana';

?>
{
  "trans.cart.title": "Your <em>shopping</em> cart",
  "trans.cart.checkout": "Go to checkout",
  "trans.cart.items": "Your cart is empty|One item in your cart|%d items in your cart",
  "trans.greeting": "Hello :name, welcome back to :place."
}

See also

  • {highlight} Colours source code on the server - PAD, PHP, HTML, CSS, JavaScript, JSON, YAML, SQL or shell - with optional line numbers and marked lines.
  • {tabs} Panels behind a row of tabs, switched by radio buttons and CSS - no JavaScript.
  • {page} Renders another page of the application - its PHP and its template - in place of the tag.