Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
bitbucket.org/zappwork/smash
Golang templating is fast and great for rendering html templates, but differs from other templating engines. Smash takes away some of the more complex configurations and restrictions. It is a simple wrapper around the Golang html/template package and is based on the Django templating syntax find documentation here (https://docs.djangoproject.com/en/1.9/ref/templates/builtins/). Most Django functionality has been ported to Golang and a list of tags and filters can be found at the end of this file. Some obscure tags and filters have been omitted from this package.
Smash adds a few functionalities and basic methods, such as extending, including, blocks and setting/changing variables in the main context.
Find documentation at GoDoc
go get bitbucket.org/zappwork/smash
package main
import (
"fmt"
"time"
"bitbucket.org/zappwork/smash"
)
func main() {
// Smash use cache default is true. This will only work when using templates stored on disk and only for development purposes.
smash.LoadWithIdentifier("example", "./tpl/extend.tmpl")
ctx := smash.Context{"title": "Smash", "spacing": 3.0, "test": 10, "elements": []string{"one", "two", "three", "four"}, "Now": time.Now()}
tpl := smash.NewTemplate("example", ctx)
fmt.Println(tpl.Parsed())
fmt.Println(tpl.String())
}
Paths can take different formats and setting the main path is optional and the same is for namespaced paths.
Set a the main template location path. This is the main location where template will be searched in.
smash.SetPath("./tests/")
tpl := smash.NewTemplate("simple-a.tmpl", smash.Context{"test": "Hello World!"})
fmt.Println(tpl.String())
Returns the current main template path.
smash.SetPath("./tests")
fmt.Println(smash.Path())
Set a namespaced template location path. This is a namespaced template path and can be used in load, include and extending templates.
smash.AddNamespacedPath("smash", "./tests/namespace1")
tpl := smash.NewTemplate("smash:template.tmpl", nil)
fmt.Println(tpl.String())
Returns the requested namespaced template path.
smash.AddNamespacedPath("smash", "./tests/namespace1")
fmt.Println(smash.NamespacedPath("smash"))
Load and parse the template found in the path and namespaces paths. This will pre-process all templates found and will speed up initial load time. This will only have any effect if the caching is used.
smash.AddNamespacedPath("smash", "./tests/namespace1")
smash.LoadAndParse()
Set a template as a string and not from file and register it to the pool.
smash.Set("id", "{{ test_var }}")
tpl := smash.NewTemplate("id", smash.Context{"test_var": "Hello World!"})
fmt.Println(tpl.String())
Load a template as from file and register it to the pool.
smash.Load("./tests/simple-a.tmpl")
tpl := smash.NewTemplate("./tests/simple-a.tmpl", smash.Context{"test_var": "Hello World!"})
fmt.Println(tpl.String())
Load a template as from file with and id and register it to the pool.
smash.LoadWithIdentifier("id", "./tests/simple-a.tmpl")
tpl := smash.NewTemplate("id", smash.Context{"test_var": "Hello World!"})
fmt.Println(tpl.String())
Use caching of templates and parsed templates. During development you may want to disable caching to see the changes that were made to the templates without restarting your whole application.
// Only use for development purposes
smash.UseCache(false)
Clear the cache manually of all loaded and parsed templates
smash.ClearCache()
Tags | Filters |
---|---|
Supported tags | Supported Filters |
extends | loop |
block | upper |
include | lower |
comment (single & multiline) | default |
for | default_if_none |
for ... empty | safe |
if, elif and else | concat |
firstof | add |
spaceless | length |
set | length_is |
now | addslashes |
capture (multiline Go >= 1.5) | capfirst |
cycle (silent not implemented) | center |
| escape
To add tags | escapejs with | divisibleby | filesizeformat Unsupported tags | first ifchanged | last load | join lorem | linebreaksbr regroup | linebreaks ssi | linenumbers templatetag | ljust url | rjust verbatim | make_list widthratio | pluralize | pprint | random | slice | slugify | striptags | title | truncatechars | truncatechars_html | truncatewords | truncatewords_html | urlencode | wordcount | wordwrap | yesno | date | time | now | timeuntil | timesince | stringformat | | Unsupported filters | surlize | surlizetrunc | sunordered_list | ssafeseq | sremovetags (Use striptags) | sphone2numeric | sget_digit | sforce_escape | sdictsortreversed | sdictsort
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.