Table of Contents

Code

View of source code with the CP code and the JavaScript SyntaxHighlighter in the FE.

Syntax Highlighting since version V1.5 r461

The main Highlighter:

Forum: CP Code - Syntax Highlighting PHP



Template

Template: template/inc_cntpart/code/JavaScript-SyntaxHighLighter.tmpl

E.g.: View of PHP-Code.

[TITLE]<h3>{TITLE}</h3>[/TITLE]
[SUBTITLE]<h4>{SUBTITLE}</h4>[/SUBTITLE]
[CODE]<pre class="brush: php; ruler: true;">
{CODE}
</pre>
<!-- CSS: {TEMPLATE}lib/syntaxhighlighter/styles/shCoreDefault.css -->
<!-- JS: {TEMPLATE}lib/syntaxhighlighter/shCore.js -->
<!-- JS: {TEMPLATE}lib/syntaxhighlighter/shBrushPhp.js -->
<!-- JS: SyntaxHighlighter.all(); -->
[/CODE]


The different highlighter can be set on the JS.

E.g. for JavaScript:

<pre class="brush: jscript; ruler: true;">
. 
. 
<!-- JS: {TEMPLATE}lib/syntaxhighlighter/shBrushJscript.js -->

The different highlighter can be viewed in the template directory template/lib/syntaxhighlighter/*.js.


PHP

The CP code set for each line break automatically a <br />. The JS also takes up this html TAG and interprets it.

To avoid this, the <br /> must be removed for the output in the FE. For this purpose, the following CP-Trigger (PHP-Script) triggers are used.

File: template/inc_script/frontend_init/cp_trigg_code_no_br.php

cp_trigg_code_no_br.php

<?php
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
    if (!defined('PHPWCMS_ROOT')) {
        die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -------------------------------------------------------------------------------------------
/**
 *********************************************************************************************
 * Simple Version 1.0
 * 10.02.12 KH: Delete all <br /> from source text in CP code
 *
 * File: CP trigger in template/inc_Script/frontend_init/cp_trigg_code_no_br.php
 
 * TAG in template for processing:  [%NoBR%]
 *********************************************************************************************
*/
 
function TRIGG_CP_CODE_NO_BR_V1($text, & $data) {
 
    // Der richtige CP:  code (11)
    // and Tag available?
 
    if    (    ($data['acontent_type'] == 11) AND                 // cp code
            ( strpos($text, '[%NoBR%]') !== FALSE) )     // TAG is set ?  // TAG vorhanden?
    {
//     dumpVar($text);
        $text = str_replace('<br />', '', $text);
        $text = str_replace('[%NoBR%]', '', $text);
 
    }
        return $text;
}
 
register_cp_trigger('TRIGG_CP_CODE_NO_BR_V1');
 
?>

Somewhere in the template between <code>....</code> the TAG [%NOBR%] is registered for the trigger to know that he is meant.