1. Go to this page and download the library: Download n5s/dtcg-tokens library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$tokens->get('color.fg'); // base -> rgb(255 255 255)
$tokens->get('color.fg', 'dark'); // dark -> rgb(0 0 0)
$tokens->get('color.fg')->forMode('dark'); // same as above
$tokens->get('color.fg')->forMode('nope'); // falls back to the base value
$tokens->get('color.accent'); // -> rgb(0 0 255) (blue, base)
$tokens->get('color.accent', 'dark'); // -> rgb(0 0 136) (blue, dark) — hoisted through the alias
use n5s\DtcgTokens\Tokens;
use n5s\DtcgTokens\Twig\TokenExtension;
use Twig\Environment;
use Twig\Extension\AttributeExtension;
use Twig\RuntimeLoader\FactoryRuntimeLoader;
$tokens = Tokens::fromFile('tokens.json');
$twig = new Environment($loader);
$twig->addExtension(new AttributeExtension(TokenExtension::class));
$twig->addRuntimeLoader(new FactoryRuntimeLoader([
TokenExtension::class => static fn (): TokenExtension => new TokenExtension($tokens),
]));
use n5s\DtcgTokens\Cache\CachedTokenFactory;
use n5s\DtcgTokens\Loader\JsonFileLoader;
$factory = new CachedTokenFactory(
loader: JsonFileLoader::fromPaths(['tokens.json']),
cache: $psr6Pool, // any Psr\Cache\CacheItemPoolInterface, or null
debug: $isDebug,
);
$tokens = $factory->create();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.