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

Element API integration #312

Closed
ghost opened this issue Feb 11, 2019 · 5 comments
Closed

Element API integration #312

ghost opened this issue Feb 11, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 11, 2019

Hi

I'm trying to integrate Seomatic in the Element Api. But it doesn't seem to give the right values.

How can I get the raw content of the seoTitle, seoDescription and the url of the seoImage?

The title of the page I'm testing is 'Case'.

var_dump($entry->seo->metaGlobalVars->seoTitle);
Output: string(58) "{seomatic.helper.extractTextFromField(object.entry.title)}"

var_dump($entry->seo->metaGlobalVars->parsedValue('seoTitle'));
Output: string(0) ""

Thanks for the help!
Katia

@khalwat
Copy link
Collaborator

khalwat commented Feb 11, 2019

Probably the reason that isn't working is that there is no entry in the context of the Element API.

I'm guessing you might just want to use the existing controllers that SEOmatic provides for obtaining meta information?

https://github.com/nystudio107/craft-seomatic#meta-container-api-endpoints

@ghost
Copy link
Author

ghost commented Feb 12, 2019

Using the existing endpoints works. But it would be nice if I could get this information (entry details and seo details of the entry) just in one call to the element api :).

But if that's not possible, we can always use the existing api endpoints.

@khalwat
Copy link
Collaborator

khalwat commented Feb 13, 2019

So you're already in the Element API, you can make whatever calls to SEOmatic that you like. Check out what the controller does:

https://github.com/nystudio107/craft-seomatic/blob/v3/src/controllers/MetaContainerController.php#L208

Ignoring the caching layer for now, you would end up doing something like:

                Seomatic::$plugin->metaContainers->previewMetaContainers($uri, $siteId, true);

But really it might be easiest to just run the controller action directly from your code to get back the info you want:

$result = Craft::$app->runAction('seomatic/meta-container/all-meta-containers', $params);

@khalwat khalwat closed this as completed Feb 13, 2019
@ursbraem
Copy link

ursbraem commented Oct 6, 2019

Bottom line: should I use seomatic for a headless site with element api, is it a valid use case and robust/versatile enough? or just add some custom fields to each entry type?

@khalwat
Copy link
Collaborator

khalwat commented Oct 10, 2019

Yes, it is a robust, valid use-case.

You can also use it with GraphQL if you prefer.

See: https://nystudio107.com/docs/seomatic/Advanced.html#headless-spa-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants