Add several pages at once to a collection


I’d like to add several page variables to a collection like this:

$arte = page('february/arte');
$pasas = page('february/pasas') ;
$pepe = page('september/pepe');
$totopo = page('september/totopo') ;

$all = // add here all the previous pages at once

How to do that without having to establish a collection first then add each one by one?

Thank you

First option:

$collection = $pages->find(['february/arte', 'february/pasas', 'september/pepe', 'september/totopo']);

Second option (if you have to define those pages in advance:

$collection = $pages->find([$arte->uri(), …]);

Third option:

$collection = new Pages($arte, $pasas,…);
1 Like

$pages->append($key, $object)
seems to be what you need… or get the pages all together like texnixe recommended.

Thank you

Would it be possible to define my page variables AND add them all at once ? such as:

$mycollection = ($arte = page('february/arte'), ($pasas = page('february/pasas'))

…etc ?

@Svnt Thanks but I am looking specifically for a way to add them all together

See the third option I added above; instead of the variables, you can of course also use page('whatever').

Thanks, but can I do something like this?

$collection = new Pages($arte=page('february/arte'), $pasas=page('february/pasas'),…);

this is… to define the pages as variables AND store them in the collection at the same time ? and still be able to access these variables later , of course

Yes, you could, but I wouldn’t do that, because your code becomes unreadable.

Ok, thank you also for the reccomendation.