Determine Entry based on URL Parameters? I have a bit of code that checks if a page's title has been manually set in a parent template, and if it has to use that, otherwise to use entry.title. This is what that bit looks like:

{% set activeTitle %}
     {% if pageTitle is defined %}
         {{ pageTitle }}
     {% else %}
         {{ entry.title }}
     {% endif %}
{% endset %}


I however have some pages like so:
http://example.com/foo/text.html?sectionId=6&amp;handle=bar&amp;entryId=170&amp;slug=somethingclever

How do I get the entry based on the parameters that are defined in the URL? And then use this entry's entry.title to set my page title?
This is a longer version answer (code wise) to the one Douglas already posted. He did a very nice job of explaining how to get a URL parameter and what to pay attention to handling the results.

I will try to show you how to build a query from multiple unknown params, so any of these combinations is possible and potentially return a single (and unique) Entry Model:

http://example.com/foo?sectionId=6&amp;entryId=170&amp;slug=somethingclever
http://example.com/foo?sectionId=6&amp;slug=somethingclever
http://example.com/foo?entryId=170  

This also tries to handle the case, the page already comes with an entry variable pre-populated or there's already a pageTitle set. So you don't do all the requests / logic on all of your pages.

{#
 # Only try parsing the params, if this page doesn't come with an `entry`
 # var pre-populated and we don't already have `pageTitle` set.
 #}
{% if not entry and pageTitle is not defined %}

    {# Get URL params #}
    {% set entryId = craft.request.getParam('entryId') %}
    {% set entrySlug = craft.request.getParam('slug') %}
    {% set sectionId = craft.request.getParam('sectionId') %}

    {# Default query #}
    {% set query = craft.entries %}

    {# Add params to the query if they are not empty #}
    {% set query = not entryId ? query : query.id(entryId) %}
    {% set query = not entrySlug ? query : query.slug(entrySlug) %}
    {% set query = not sectionId ? query : query.sectionId(sectionId) %}

    {# Now try to get that entry and set our own `entry` var #}
    {% set entry = query.first() %}

{% endif %}

{# Set the entry title. Also handle the case our query didn't find anything #}
{% set entryTitle = entry ? entry.title : 'Title for a page that doesn’t exist' %}

{# Set the page's title #}
{% set activeTitle = pageTitle is defined ? pageTitle : entryTitle %}


Useful links for this code: craft.request and Ternary operator in Twig.