# jsph

> use php/asp tags with javascript language to produce output from templates

Latest version **1.1.0** (published 2014-03-18) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install jsph
pnpm add jsph
yarn add jsph
bun add jsph
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2014-03-18 |
| First published | 2014-03-03 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Brent Larsen |
| Maintainers | brentoboy |
| Keywords | php, js, asp, template |

## Links

- npm: https://www.npmjs.com/package/jsph
- Repository: https://github.com/brentoboy/jsph
- Issues: https://github.com/brentoboy/jsph/issues
- npm.io page: https://npm.io/package/jsph

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2014-03-18
- 1.0.0 — 2014-03-04
- 0.1.3 — 2014-03-04
- 0.1.2 — 2014-03-03
- 0.1.1 — 2014-03-03

## README

# jsph

jsph (pronounced like the name joseph) is an extreemly lightweigth implementation
of php/asp style open/close tags with javascript used as the coding language.

if you know javascript, and you know php, then you already know jsph.

if jsph is too feature poor for you, you shoud consider ejs instead, this is basically
the same thing scaled back to have absolutely zero non-essential features.

## Installation
	npm install jsph

## Usage

jsph supports either php style tags, or asp style tags <? ... ?>  or <% ... %>
it also supports <?= ... ?> for easily outputing computed values.

'nough sed.

just in case the above description isnt sufficient to get you started, here is some sample jsph:


	var jsph = require('jsph');
	console.log(jsph.render("today is <?= new Date().toJSON().slice(0,10) ?>")
	console.log(jsph.renderFileSync('./myfile.jsph'));
	jsph.renderFile('.myfile.jsph', function(err, output) {
		if (err) console.log(err);
		else console.log(ouput);
	});

you can also pass an object into a template and access it via "this"

	var template = "Hello, <?= this.name ?>!";
	var templateParams = { name: "World"}
	var output = jsph.render(template, templateParams);
	console.log(output); // -> "Hello, World!"


## Example Template

	<?	var someValues = ["World", "node.js", "jsph"];
		for(i in someValues) { ?>
		Hello <?= someValues[i] ?>!
	<?	} ?>

the above code would output the following

	Hello World!
	Hello node.js!
	Hello jsph!


## Example of using Compile()

if you intend to use the same template multiple times, you can save some time by
compiling it once and using the compiled version of the template to render rather
than calling jsph.render ... which compiles the template on the fly.

	var jsph = require('jsph');
	var template = "Hello, <?= this.name ?>!";
	var renderTemplate = jsph.compile(template);
	var output = renderTemplate({ name: "test"});
	colsole.log(output); // -> "Hello, test!"

	// there is also a compileFile(path, vars, callback(err, renderFunction))
	// and compileFileSync(path, vars)

## Example usage in html / js running in a browser window

NOTE: Only compile() and render() are supported in the browser, the "renerFile" and "renderFileSync" are not supported client side.

	<html>
		<head>
			<title>json template sample</title>
			<script src="../src/jsph.js"></script>
		<head>
		<body onload="on_body_load();">
			<h1> here is some dynamically created content </h1>
			<div id="target"></div>
			<script id="template" type="text/template">
				<ul>
				<? for (var i = 1; i <= 100; i++) {
					?><li>entry #<?= i ?><?
				} ?>
				<ul>
			</script>
			<script type="text/javascript">
				function on_body_load() {
					var template = document.getElementById("template").innerHTML;
					var renderTemplate = jsph.compile(template);
					var targetDiv = document.getElementById("target");
					targetDiv.innerHTML = renderTemplate();
				}
			</script>
		</body>
	</html>

---
_Source: https://npm.io/package/jsph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
