1

I want to configure deeplinks for an app and want to set up 'universal links'. Right now I'll send an entry id to the element api to get the right content. But with universal links I didn't have a entry id, only a url. Based on the url I'll need to get the right entry instead of based on the entry id.

Down here is my current endpoint to get the right entry based on a id. But if I didn't have an id how can I get the entry id based on the url.

for example website.com/pages/welcom has entry id 123, in the app I can open it with sending 123 to the api endpoint. With universal links I open a link from my mail app for example then the app launches and I can send 'website.com/pages/welcom' to the api but how I'll get the right content from that page that has entry id 123.

'api/pages/<entryId:\d+>' => function($entryId) {

        requireLogin();

        return array(
            'elementType' => 'Entry',
            'criteria' => ['section' => 'pages', 'id' => $entryId],
            'transformer' => function(EntryModel $entry) {



                $bodyBlocks = [];
                foreach ($entry->contentBlokken as $block) {
                    switch ($block->type->handle) {
                        case 'tekst':
                            $bodyBlocks[] = [
                                'text' => $block->description->getParsedContent(),
                            ];
                            break;
                    }
                }

                return array(
                    'id' => $entry->id,
                    'title' => $entry->title,
                    'description' => $bodyBlocks,
                );
            }
        );
    },
  • Sorry, but I don't think I'm following 100%. Can you expand the question and maybe add some example URLs and code to elaborate? – Brad Bell Mar 13 at 22:03
  • @BradBell I updated my question hope I'll make it more clear. – Maarten Heideman Mar 15 at 10:45
2

I'm assuming that "welcome" is also your page slug.

You could query the craft_elements_i18n table (pseudo code):

$sql = "select id from craft_elements_i18n where slug = 'welcome' limit 1"
$result = get($sql);
$entry_id = $result['id'];

Then feed that into your function. Replace 'welcome' with a read of the uri to make it dynamic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.