Skip to content

Instantly share code, notes, and snippets.

@pftnhr
Last active October 11, 2023 20:05
Show Gist options
  • Save pftnhr/6210e410339d2513c8d2cf1fbebe7d7a to your computer and use it in GitHub Desktop.
Save pftnhr/6210e410339d2513c8d2cf1fbebe7d7a to your computer and use it in GitHub Desktop.
[datenstrom-yellow] A ToDo page/Dashboard

yellow-todo

... was created by me to have my todo list on the website. Now I use it as a kind of dashboard that shows my drafts and unlisted posts.

<nav>
<ul id="menu">
<?php foreach ($pages as $page): ?>
<li><a<?php echo $page->isActive() ? " class=\"active\" aria-current=\"page\"" : "" ?> href="<?php echo $page->getLocation(true) ?>"><?php echo $page->getHtml("titleNavigation") ?></a></li>
<?php endforeach ?>
<?php if ($this->yellow->user->isUser("name") == "<YOUR_USERNAME>") { ?>
<?php foreach ($todos as $todo): ?>
<li><a<?php echo $todo->isActive() ? " class=\"active\" aria-current=\"page\"" : "" ?> href="<?php echo $todo->getLocation(true) ?>"><?php echo $todo->getHtml("titleNavigation") ?></a></li>
<?php endforeach ?>
<?php } ?>
</ul>
</nav>
<?php $this->yellow->layout("header") ?>
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php echo $this->yellow->page->getContentHtml() ?>
<h2>Drafts</h2>
<?php $drafts = $this->yellow->content->index(true)->filter("status", "draft")->sort("published", false) ?>
<ul>
<?php foreach ($drafts as $draft): ?>
<li>
<a class="entry-link" href="<?php echo $draft->getLocation(true) ?>"><?php echo $draft->getHtml("title") ?></a>
</li>
<?php endforeach ?>
</ul>
<h2>Unlisted</h2>
<?php $unlisteds = $this->yellow->content->index(true)->filter("status", "unlisted")->sort("published", false) ?>
<ul>
<?php foreach ($unlisteds as $unlisted): ?>
<li>
<a class="entry-link" href="<?php echo $unlisted->getLocation(true) ?>"><?php echo $unlisted->getHtml("title") ?></a>
</li>
<?php endforeach ?>
</ul>
<?php $this->yellow->layout("footer") ?>
<!---------------------------
todo.php
Dexcription: This simple extension adds a new status "todo" to Yellow that I use to create a kind of dashboard that can only be accessed when I am logged in. See "navigation-snippet.html".
The todo.html is the associated layout file where I display drafts and unlisted pages.
Created by Robert Pfotenhauer on 03.10.23.
---------------------------->
<?php
// Todo extension
class YellowTodo {
const VERSION = "0.8.18";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle page meta data
public function onParseMetaData($page) {
if ($page->get("status")=="todo") $page->visible = false;
}
// Handle page layout
public function onParsePageLayout($page, $name) {
if ($this->yellow->page->get("status")=="todo" && $this->yellow->lookup->getRequestHandler()=="core") {
$errorMessage = "";
if ($this->yellow->extension->isExisting("edit")) {
$errorMessage .= "<a href=\"".$this->yellow->page->get("editPageUrl")."\">";
$errorMessage .= $this->yellow->language->getText("todoPageError")."</a>";
}
$this->yellow->page->error(420, $errorMessage);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment