Nxdom Framework

Nusantara eXtreme Development Object Model — dokumentasi resmi

Variabel per file & include

Menumpuk beberapa file template, men-assign variabel ke namespace nama file, lalu memparse atau meng-include file PHP yang menghasilkan HTML. Di controller gunakan assignFileVar() yang meneruskan ke NexaDom::assign_file_var().

NexaDom.php · add_file assign_file_var pparse_file include_file

1. Alur umum

  1. add_file('path/relatif/ke/root/template.html') — mendaftarkan file (path relatif terhadap $this->root NexaDom). File harus ada di disk.
  2. assign_file_var('path/relatif/ke/root/template.html', 'nama_var', $nilai) — men-set variabel hanya untuk konteks file tersebut (disimpan di _tpldata per file).
  3. pparse_file(...) — memuat dan memproses file yang sudah terdaftar.

2. File sementara

add_tempfile($pathAbsolut) — mengregistrasi file dengan path absolut (mis. hasil generate), tanpa mengasumsikan root template.

3. Include PHP → template

include_file($pathFilePhp, ...) menjalankan file PHP dengan include, menangkap output buffer, lalu memproses hasilnya sebagai template (NEXA, variabel, dll.) lewat pipeline pparse. Berguna untuk fragmen yang dibangun lewat skrip PHP sebelum NexaDom merapikan sintaks template.

4. Dari NexaController

$this->assignFileVar('partials/header.html', 'title', $title); // setara: $this->template->assign_file_var(...)

Pastikan file sudah add_file di instance NexaDom yang sama sebelum assign_file_var.

5. Root direktori

set_rootdir(string $dir) mengubah folder root template; semua add_file berikutnya mengacu ke path relatif dari root baru.

Lanjut

Section & kompresi · API blok lanjutan · Indeks Helper · Beranda.