Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K2 extension #365

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

K2 extension #365

wants to merge 21 commits into from

Conversation

johanjanssens
Copy link
Member

@johanjanssens johanjanssens commented Jun 7, 2020

This PR closes #364 and implements readonly support for K2: articles, categories and fields and attachments through the ext:k2 extension namespace. Following collection models are available:

Collection models

  • ext:k2.model.articles
  • ext:k2.model.categories
  • ext:k2.model.fields
  • ext:k2.model.attachments

Example

Setting up an articles collection is very simple. For example to list all the published articles from category with id 1 sorted alphabetically by title you do:

---
collection:
    model: ext:k2.model.articles
    state:
        published: 1
        category: 1 
        sort: title
---

<ul>
<? foreach(collection() as $article): ?>
	<li><?= $article->title; ?></li>
<? endforeach ?>
</ul>

article() template function

Aarticle() template function has been been introduced that allows to get a single article by it's id or alias.

For example to retrieve the article with id = 1

<article>
   <h1><?= article(1)->title ?></h1>
    <p><?= article(1)->text ?></p>
</article> 

For example to retrieve the article with alias = 'my-article'

<article>
   <h1><?= article('my-article')->title ?></h1>
    <p><?= article('my-article")->text ?></p>
</article> 

Defining custom aliases

Using K2 article aliases directly could results into articles not being found it the alias is edited (by accident). To resolve that and to still make it possible to reference an article by a string you can define your own custom static aliases through the configuration

For example define an alias called about-us and link it to article with id = 1

<?php
return array(
    'extensions' =>
    [
	'ext:k2.model.articles'  =>
	[
		'aliases' => [
			'about-us' => 1
		]
	]
   ]
);

You can now do

<article>
   <h1><?= article('about-us')->title ?></h1>
    <p><?= article('about-us')->text ?></p>
</article> 

@johanjanssens johanjanssens self-assigned this Jun 7, 2020
@johanjanssens johanjanssens changed the title K2 support K2 extension Jun 20, 2020
@johanjanssens johanjanssens added the invalid This doesn't seem right label Apr 6, 2021
@johanjanssens johanjanssens deleted the feature/364-K2 branch April 6, 2021 20:32
@johanjanssens johanjanssens restored the feature/364-K2 branch April 9, 2021 16:43
@johanjanssens johanjanssens reopened this Apr 9, 2021
@johanjanssens johanjanssens added this to the Backlog milestone Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

K2 extension
1 participant