Skip to content

Menampilkan faq.data dari Page (parent page) ke semua Child-nya #275

Closed Answered by taufik-nurrohman
bungfrangki asked this question in Q&A
Discussion options

You must be logged in to vote

Kalau isinya JSON, bisa diiterasikan, sehingga markup HTML tidak perlu ditulis di dalam data:

{
  "title": "FAQ",
  "list": [
    {
      "q": "Question 1",
      "a": "Answer 1"
    },
    {
      "q": "Question 2",
      "a": "Answer 2"
    }
  ]
}

Terus di layout bisa begini:

<h2>
  <?= $page->faq['title'] ?? 'Default'; ?>
</h2>
<?php if (!empty($page->faq['list'])): ?>
  <?php foreach ($page->faq['list'] as $v): ?>
    <h3>
      <?= $v['q'] ?? 'Default'; ?>
    </h3>
    <p>
      <?= $v['a'] ?? 'Default'; ?>
    </p>
  <?php endforeach; ?>
<?php endif; ?>

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@bungfrangki
Comment options

Answer selected by bungfrangki
Comment options

You must be logged in to vote
2 replies
@bungfrangki
Comment options

@taufik-nurrohman
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants