forkbb
forkbb copied to clipboard
Syntax to include files in layout files
I like to use PHP INCLUDE to add a standard footer I have for the many pages on a site (outside the forum). Is there a syntax I can use to do this in the layout files since they do not allow PHP code? It would be equivalent to
<?php include 'path_to_file/footer.html'; ?>
Starting from revision 69, default templates are located in the /app/templates/_default/ folder. If you want to make changes to the template, then you must copy this template to the /app/templates/_user/ folder. And make changes to it.
PHP code can easily be included in the template, since templates are compiled into regular PHP for further execution. example /app/templates/_default/admin/form.forkbb.php
@section ('og:image') @if ($p->ogImageUrl) <img class="f-og-img" src="{{ $p->ogImageUrl }}" alt="{{ \basename($p->ogImageUrl) }}"> @endif @endsection
@extends ('layouts/admin')
<section class="f-admin @if ($p->classForm) f-{{ \implode('-form f-', $p->classForm) }}-form @endif">
<h2>{!! __($p->titleForm) !!}</h2>
<div class="f-fdiv">
@if ($form = $p->form)
@include ('layouts/form')
@endif
</div>
</section>
compiled file /app/cache/_admin-form-26e80a48caa54e049be079a870607340.php
<?php
declare(strict_types=1);
use function \ForkBB\{__, num, dt, size, url};
?><?php $this->beginBlock('og:image'); ?><?php if ($p->ogImageUrl): ?> <img class="f-og-img" src="<?= \htmlspecialchars((string) $p->ogImageUrl, \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8') ?>" alt="<?= \htmlspecialchars((string) \basename($p->ogImageUrl), \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8') ?>"><?php endif; ?><?php $this->endBlock(); ?>
<?php $this->extend('layouts/admin'); ?>
<section class="f-admin<?php if ($p->classForm): ?> f-<?= \htmlspecialchars((string) \implode('-form f-', $p->classForm), \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8') ?>-form<?php endif; ?>">
<h2><?= __($p->titleForm) ?></h2>
<div class="f-fdiv">
<?php if ($form = $p->form): ?>
<?php include $this->prepare('layouts/form'); ?>
<?php endif; ?>
</div>
</section>
Thank you, this makes things much easier for me.
Just to be clear for anyone else wanting to do this who may be unclear about the above, the file you want to @include must exist in the _user directory in the filename format
_user/layouts/myFile.forkbb.php
and referenced as
@include ('layouts/myFile')
@include does not appear to support absolute path names, so if you want to include a file located outside the ForkBB directory structure, I assume a symbolic link may work, although I haven't tried that.
Topic Шаблоны (Templates)