r4j4h/jspackager-html-tagger

Simple bare bones HTML tag generator for <script> and <link> tags

1.0 2015-06-02 00:42 UTC

This package is not auto-updated.

Last update: 2024-12-21 19:19:33 UTC


README

Tagger is a simple bare bones converter from file paths to <script> and <link> HTML tags written in PHP.

Installation

  1. Install Composer
  2. composer require 'r4j4h/jspackager-html-tagger:1.0'

Usage

Basics

echo $tagger->getScriptTag('myscript.js');
<script type="text/javascript" src="myscript.js"></script>
echo $tagger->getStylesheetTag('myscript.css');
<link href="myscript.css" rel="stylesheet" type="text/css" />

Custom Media Type for Stylesheets

$tagger->setStylesheetMediaType('screen');
echo $tagger->getStylesheetTag('myscript.css');
<link href="myscript.css" media="screen" rel="stylesheet" type="text/css" />

Cache Bust

echo $tagger->getStylesheetTag('myscript.css', "text");

$this->assertEquals(

<link href="myscript.css?cb=text" rel="stylesheet" type="text/css" />
$tagger->cacheBustKey = 'mtime';
echo $tagger->getScriptTag('myscript.js', 123);

$this->assertEquals(

<script type="text/javascript" src="myscript.js?mtime=123"></script>

Extension Based Detection

echo $tagger->getTag('myscript.js');
echo $tagger->getTag('myscript.css');
<script type="text/javascript" src="myscript.js"></script>
<link href="myscript.css" rel="stylesheet" type="text/css" />